I agree, making references to the files is a more robust way of doing things. In fact, that's the way I normally work.
I'm in the process of learning more about 'BLOBS' and exploring the reality of storing images in a db/table versus the filesystem.
Anyway, thanks for the pointers. :)
John
At 3:44 PM -0600 on 1/26/04, Paul Miller wrote:
While I totally agree with Ryan, there are instances where I have found that people do not follow best practices, namely Oracle (Oracle File Storage) and many MySQL/PHP programs out there (OPT and Help Center Live). So here is some code addressing both.
You would probably need an interpreter file. Something like image.php and call images like image.php?ID=house.
Then in your code, you grab the blob or file info and print it out after you set the headers like this:
================================================= THE DB OPTION (local file system storage): ================================================= <?php
$sql = "select image_blob_column, mime_type from images where image_ext_id = '$ID'";
$results = sql_query($sql, $db_id); if ($row_file = sql_fetch_array($results)){ // Set the headers Header("Content-Type: ".$row_file["mime_type"]); // Gif or Jpeg Header("Content-Disposition: inline"); // Tells the browser to display it // in the browser if it is opened up by itself Header("Content-Length: ".count($row_file["image_blob_column"])); echo $row_file["image_blob_column"]; }
?> ================================================= THE FILE OPTION (local file system storage): ================================================= <?php
$sql = "select file_path, mime_type from images where image_ext_id = '$ID'";
$results = sql_query($sql, $db_id); if ($row_file = sql_fetch_array($results)){ // Set the headers Header("Content-Type: ".$row_file["mime_type"]); // Gif or Jpeg Header("Content-Disposition: inline"); // Tells the browser to display it // in the browser if it is opened up by itself Header("Content-Length: ".filesize($row_file["file_path"])); $fp=fopen($row_file["file_path"], "rb"); fpassthru($fp); } ?>
The GD library is for creating new images using specified parameters or editing an image.
HTH
- Paul
-----Original Message----- From: Ryan Jameson (USA) [mailto:RJameson@xxxxxxxxxxx] Sent: Monday, January 26, 2004 3:28 PM To: php-db@xxxxxxxxxxxxx Subject: RE: Images stored in a db - how to get them?
about once a quarter this question comes up and the answer is always the same. Don't store them in the database, just store filenames and store the files in the filesystem. That way you just generate a link and treat it like any other image. Then when you query the database you would create img tags with src property set to the image. You probably don't want to store FULL path info, just enough to find the image.
<>< Ryan
-----Original Message----- From: John T. Beresford [mailto:john-nic@xxxxxxxxxxxxx] Sent: Monday, January 26, 2004 2:23 PM To: php-db@xxxxxxxxxxxxx Subject: Images stored in a db - how to get them?
Hello All,
I am interested in storing images in a table. My question is - What is the proper way of retrieving the images and displaying them on a web page?
Will I need to go through the GD library and create an image from the information stored in the table?
While PHP is not new to me, images in db's is. Specifically, when info is returned, it's usually in the form of:
$var=$row['FieldName'];
What would I then do with the 'BLOB' information? Is that where the GD image tools come in play?
Any URL's or small hints to point in the right direction would be very much appreciated.
Thanks, John --
-- =========================== John T. Beresford Apple Certified Technical Coordinator http://www.deewi.com/ 405.760.0794
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php