Possible Duplicate:
php: recreate and display an image from binary data
I want to display in my page the image I got from this code:
$contents = fread($handle, filesize($filename));
How do I display it?
Possible Duplicate:
php: recreate and display an image from binary data
I want to display in my page the image I got from this code:
$contents = fread($handle, filesize($filename));
How do I display it?
You have to print out image's content and set proper header depends on the filetype.
Example:
<?php
$contents = fread($handle, filesize($filename));
header('Content-Type: image/jpeg');
echo $contents;
If you already have a file that is outputting HTML, and within that page you would like to show an image, you need to use the <img>
tag. You can call another file that does what the other poster suggested to output the contents. But the Content-Type
you would output depends on the image MIME type. If it's a PNG file, then you would use a different header parameter:
<?php
$contents = fread($handle, filesize($filename));
header('Content-Type: image/png'); // or image/gif, depending on what $filename is.
echo $contents;
Your other option is to output this image inline using data URI:
Here is an example:
<?php
// take note that this is for PNG files - just change it to JPG or GIF depending on whatever your image is
$filename = 'image.png';
echo 'The following image is a PNG file... <img src="data:image/png;base64,'.base64_encode(file_get_contents($filename)).'" />';
?>