【发布时间】:2014-12-07 19:05:45
【问题描述】:
我试图在 fopen 之后回显图像并对其进行 fread,但它显示为 ascii 代码而不是图像格式。
我找到了答案:
Fopen function opens JPEG image as text
我在代码中实现了 header() 行,但它似乎试图将我当前的 php 文件打开为 jpg 而不是图像。
这是我的代码:
$filename = $n.".jpg";
//echo $n.'.jpg'; prints image_name.jpg
$fp = fopen($filename, "r");
$data = fread($fp, filesize($filename));
header('Content-type: image/jpg'); //without the header line I can print the ascii
echo $data; //I want to print my $data as image format not ascii
fclose($fp);
(我不知道这是否重要,但我使用的是最新版本的 XAMPP 和 W7)
提前致谢
【问题讨论】:
-
这可能是您浏览器的缓存问题。尝试真正刷新页面请求。
-
这段代码对我来说没有任何修改。