943,186 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1149
  • PHP RSS
Jul 11th, 2010
0

Display Images from MySQL DB using PHP

Expand Post »
Hi There Everyone.

Could anyone assist me in the correct method of displaying images from my mysql db. I want to display multiple images on my page.

This is the code I have. I got this from a post from DaniWeb. Hope I did the code tags correctly.

php Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. require 'library/config.php';
  4. require 'library/opendb.php';
  5. ?>
  6. <?php
  7. header('Content-type: image/JPG');
  8.  
  9. @mysql_connect($dbhost, $dbuser, $dbpass) or die("Can not connect to database: ".mysql_error());
  10. @mysql_select_db($dbstore) or die("Can not select the database: ".mysql_error());
  11.  
  12. $query = mysql_query("SELECT id, type, content FROM upload");
  13. while($row = mysql_fetch_array($query)){
  14. print $row['content'];
  15. }
  16. ?>

Thanks allot.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
LRNPHP is offline Offline
57 posts
since Jul 2010
Jul 12th, 2010
0
Re: Display Images from MySQL DB using PHP
What data type did you use for 'content?' Is it blob?
I think it would be better if you don't save the image itself on the database. Instead save just the file name and path where it was uploaded. When you have the path you can then show the images by doing <img src = '<?php echo $content ?>'>
Reputation Points: 14
Solved Threads: 5
Newbie Poster
Shinehah is offline Offline
23 posts
since May 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: problems with preg_replace on elements in an array
Next Thread in PHP Forum Timeline: aptana, mysql-server, php





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC