displaying uploaded image

Reply

Join Date: Dec 2007
Posts: 24
Reputation: chitra1 is an unknown quantity at this point 
Solved Threads: 1
chitra1 chitra1 is offline Offline
Newbie Poster

displaying uploaded image

 
0
  #1
Jun 1st, 2008
Hi,

I am uploading images in a form. But it only sends the images in a folder 'upload' and send only the file name to the database. How do I send the image to the database and retrieve it for display.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 74
Reputation: Vai is an unknown quantity at this point 
Solved Threads: 5
Vai Vai is offline Offline
Junior Poster in Training

Re: displaying uploaded image

 
0
  #2
Jun 1st, 2008
you are doing fine. Don't store the actual image in your database. To display you can do something like this:
  1. <?php
  2. // just so we know it is broken
  3. error_reporting(E_ALL);
  4. // some basic sanity checks
  5. if(isset($_GET['image_id']) && is_numeric($_GET['image_id'])) {
  6. //connect to the db
  7. $link = mysql_connect("localhost", "username", "password") or die("Could not connect: " . mysql_error());
  8.  
  9. // select our database
  10. mysql_select_db("database_name") or die(mysql_error());
  11.  
  12. // get the image from the db
  13. $sql = "SELECT image FROM TABLE WHERE image_id=0";
  14.  
  15. // the result of the query
  16. $result = mysql_query("$sql") or die("Invalid query: " . mysql_error());
  17.  
  18. // set the header for the image
  19. header("Content-type: image/jpeg");
  20. echo mysql_result($result, 0);
  21.  
  22. // close the db link
  23. mysql_close($link);
  24. }
  25. else {
  26. echo 'Please use a real id number';
  27. }
  28. ?>
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 4
Reputation: iFuseDan is an unknown quantity at this point 
Solved Threads: 1
iFuseDan iFuseDan is offline Offline
Newbie Poster

Re: displaying uploaded image

 
0
  #3
Jun 2nd, 2008
Only think I will point out,

Is that the uploaded image when stored would have to be converted to jpeg for that to exclusively work. When working with files you have the option of giving the uploaded images specific filenames and then rendering them through the use of functions such as imagecreatefromjpeg and imagejpeg. What you might want to do instead of using files and expanding on the database idea, would be to store the mime-type, rather then returning each image as an apparent jpeg.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC