Reputation: 401
I want to display an uploaded images into my web page.For doc files i used file_get_contents for displaying the data(not displaying exactly) but in case of images i dont have any idea.Plz tell me
Upvotes: 1
Views: 992
Reputation: 1079
are u storing the image as a file or as a binary data?
if file,
use HTML IMG element.
if binary,
read the bytes and create the image using php gdlibrary
follow this
try it and let me know
Upvotes: 0
Reputation: 5345
Use <img> tag in your code. It will display the require image in your web page . In image tag , you need specify the image path.
<img src="/home/pavunkumar/my_img.gif" alt="Not able to bring out" >
Here , alt attribute is used to say message , when the image is not able to display in the page because of some other issues, such as size,etc.
Upvotes: 0
Reputation: 401172
There are two possible solutions.
For the first one to work, your image has to be accessible via your web-server (i.e. be in a sub-directory of your document root) ; then, you just have to use an <img>
tag that points to that image :
<img src="sub-directory/your-image.jpg" alt="my image" />
Of course, up to you to adapt the path to the image ;-)
In this situation, you'll have to use some PHP script to serve the image, and call that PHP script using an <img>
tag :
<img src="serve-image?php.id=1234" alt="your image" />
Or like this :
<img src="serve-image.php?img=my-image-name.jpg" alt="your image" />
And this serve-image.php script will just :
Content-type
header -- see the header
function.readfile
function.For instance, using something like this should not be permitted (the script should return, for instance, a 404 error) :
<img src="serve-image.php?img=../../../etc/passwd" alt="trying to be bad" />
Upvotes: 2