By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,039 Members | 1,824 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,039 IT Pros & Developers. It's quick & easy.

php code to display image from mysql db

P: 4
I have used the code of 'Atli' posted on Nov, 23 2007 to upload the images into the mysql database and it's working fine but i need some more help that is..

how to display image on browser that is stored in mysql database using php code?

Nov 19 '11 #1
Share this Question
Share on Google+
5 Replies

P: 43
can you paste the URL to that post which you referred?
Nov 19 '11 #2

P: 4
Hi.. pradeepkr13, The below is the url of the page consisting the code i referred.
Nov 20 '11 #3

P: 43
He has written everything, see,
Phase 3: Listing all existing files
Nov 20 '11 #4

P: 4
Yes, I have gone through the Phase 3 code, where in instead of image, a link is displayed to download the image. But I want to display the image instead download.
I will be very thankful, if you help me to solve this issue.
Nov 21 '11 #5

P: 43
He says,

"When a browser requests a file from a HTTP server, the server response includes info on what exactly it contains. These bits of info are called headers. The headers usually include infor on the type of data being sent, the size of the response, and in the case of files, the name of the file."
We start simply by reading the ID sent by the link in phase 3. If the ID is valid, we fetch the information on the file who's ID we received, send the headers, and finally send the file data."

And this is how he is showing the image ....

Expand|Select|Wrap|Line Numbers
  1. <a href='get_file.php?id={$row['id']}'>Download</a>
Note: get_file.php is another php file which does no HTML thing. It solely sends headers and the image in binary format.
So You should use two PHP files, 1 having HTML code (with img tag) and another just dumping the image with its headers. Something like this,
Expand|Select|Wrap|Line Numbers
  1. <img src='get_file.php?id={$row['id']}'>
Nov 22 '11 #6

Post your reply

Sign in to post your reply or Sign up for a free account.