Now, after you upload your image to the database, what's next? Of course we need a way to display it to users. Here is the script to retrieve image information from database then displaying to the users.
<?php // image.php - by Hermawan Haryanto <hermawan@dmonster.com> // Example PHP Script, demonstrating Storing Image in Database // Detailed Information can be found at http://www.codewalkers.com
// database connection $conn = mysql_connect("localhost", "user", "password") OR DIE (mysql_error()); @mysql_select_db ("hermawan", $conn) OR DIE (mysql_error()); $sql = "SELECT * FROM image WHERE image_id=".$_GET["iid"]; $result = mysql_query ($sql, $conn); if (mysql_num_rows ($result)>0) { $row = @mysql_fetch_array ($result); $image_type = $row["image_type"]; $image = $row["image"]; Header ("Content-type: $image_type"); print $image; } ?>
Example, you have image with ID = 3, then you should call that file using this method <img src='image.php?iid=3'>. It's simple right? On the index.php, I've been add a link to display the page on the file, which print out an HTML tag to display the image.php file, take a re-look at index.php.