可能重复:
php: recreate and display an image from binary data如何显示我从fread()获得的图像?
我想在我的网页,以显示我从这个代码得到的图像:
$contents = fread($handle, filesize($filename));
如何显示呢?
可能重复:
php: recreate and display an image from binary data如何显示我从fread()获得的图像?
我想在我的网页,以显示我从这个代码得到的图像:
$contents = fread($handle, filesize($filename));
如何显示呢?
你要打印出的图像的内容,并设置适当的标题依赖于文件类型。
例子:
<?php
$contents = fread($handle, filesize($filename));
header('Content-Type: image/jpeg');
echo $contents;
如果您已经有在输出HTML文件,并在该网页中您想显示的图像,您需要使用<img>
标签。你可以调用另一个文件来做另一个海报建议输出内容的文件。但是您输出的Content-Type
取决于图像的MIME类型。此图片内嵌使用data URI
<?php
$contents = fread($handle, filesize($filename));
header('Content-Type: image/png'); // or image/gif, depending on what $filename is.
echo $contents;
你的另一个选择是输出:如果它是一个PNG文件,那么你可以使用不同的页眉参数
下面是一个例子:
<?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)).'" />';
?>
其实@rationalboss,你可能需要把你刚才的回答和BASE64_ENCODE($内容),而不是BASE64_ENCODE($文件名) –
有意义的一部分,我更新了我的答案。 – rationalboss
能你给出明确的例子? – pheromix
@pheromix看看我的编辑。 – hsz