How can I retrieve a picture from my database in PHP? [closed]
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this questionI've stored an image file on my local drive and the path to that image in my datab开发者_如何学编程ase. How can I retrieve the image for displaying it in PHP?
Select the data from the DB into variables ($path and $image_name).
echo it (in your view file):
echo "<img src='{$path}/{$image_name}' />";
If you're trying to write a script to serve the image up on demand, you'll want to take a look at the readfile()
function: http://php.net/manual/en/function.readfile.php
You should store the content-type that was sent when the file was originally uploaded too. Keep this with the other information you've saved about the image in the database.
精彩评论