【发布时间】:2011-02-15 03:43:53
【问题描述】:
我正在向我的浏览器显示以下 html(firefox 可以工作,但 chrome 和 safari 不能)。 Firefox 下面显示的内容按预期工作,但 safari 和 chrome 显示一个蓝色问号,周围有一个框。
<html>
<head>
<title>test</title>
</head>
<body>
<img src='pixel.php' />
</body>
</html>
我的php代码如下: (像素.php)
// send the right headers
$expiry = 0;
header('Expires: 0');
header('Cache-control: private, max-age=0');
header('Content-Type: image/gif');
header('Content-Length: ' . filesize($fileName));
// get a file pointer to the image
$fp = fopen($fileName, 'rb');
// dump the picture and stop the script
fpassthru($fp);
1x1t.gif 文件与脚本存在于同一目录中,并且在 Firefox 中一切正常 - 但是 safari 和 chrome 显示一个蓝色问号...
我需要做些什么才能让 safari 和 chrome 按预期运行?
【问题讨论】:
-
您可能希望切换到使用 readfile() 而不是 fpassthru()。 fpassthru 将在将文件发送到客户端之前将其放入内存中。如果大文件超过脚本的 memory_limit,这将失败。 readfile() 将自动以小块发送文件。至于 safari/chrome,试着保存那个蓝色?通过右键单击,看看会发生什么。也许有一个 PHP 标头潜伏在 Firefox 可以解决,但 Safari/Chrome 不能。
标签: php firefox safari google-chrome cross-browser