开发者

How can I retrieve a picture from my database in PHP? [closed]

开发者 https://www.devze.com 2023-01-05 03:41 出处:网络
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

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 question

I'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.

0

精彩评论

暂无评论...
验证码 换一张
取 消