2012-08-10 53 views
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; 

然后浏览器只读取一次文件。有人知道为什么吗?

+0

我的猜测是因为你打电话头和读文件 – 2012-08-10 14:10:15

+0

@SandeepBansal这似乎不合理;标题只是设置内容类型。 – 2012-08-10 14:19:28

+0

您不应该通过扩展名找到内容类型。请使用['Fileinfo'](http://us2.php.net/manual/en/ref.fileinfo.php)PECL扩展名。 – 2012-08-10 14:21:07

回答

2

出于测试目的,尝试从一个控制台通过

firefox -safe-mode -no-remote 

开始你的Firefox暂时禁用所有的扩展。也许其中一个扩展引起了这个问题。

+0

同意。 Firebug本身往往会加载一些资源两次。 – Tchoupi 2012-08-10 14:49:50

相关问题