2
我有一个记录印象然后显示图像的PHP脚本。为什么我的浏览器会得到两次图像?
// Determine which header to send.
$parts = explode('.', $tool->filename);
header("Content-Type: image/{$parts[1]}");
readfile('files/'.$tool->filename);
由于某些原因,Firefox获取文件两次。这是日志。
00:00:01.268 0.023 1211 182 GET 200 image/png http://localhost/ap/image.php?aid=1&t=6
00:00:01.347 0.162 1185 182 GET 200 image/png http://localhost/ap/image.php?aid=1&t=6
你可以看到他们相隔一秒钟。如果我按如下方式更改脚本。
// Determine which header to send.
$parts = explode('.', $tool->filename);
//header("Content-Type: image/{$parts[1]}");
//readfile('files/'.$tool->filename);
echo 1;
然后浏览器只读取一次文件。有人知道为什么吗?
我的猜测是因为你打电话头和读文件 – 2012-08-10 14:10:15
@SandeepBansal这似乎不合理;标题只是设置内容类型。 – 2012-08-10 14:19:28
您不应该通过扩展名找到内容类型。请使用['Fileinfo'](http://us2.php.net/manual/en/ref.fileinfo.php)PECL扩展名。 – 2012-08-10 14:21:07