Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么Safari和Chrome不显示我的gif,而是显示一个蓝色问号?_Php_Firefox_Safari_Google Chrome_Cross Browser - Fatal编程技术网

Php 为什么Safari和Chrome不显示我的gif,而是显示一个蓝色问号?

Php 为什么Safari和Chrome不显示我的gif,而是显示一个蓝色问号?,php,firefox,safari,google-chrome,cross-browser,Php,Firefox,Safari,Google Chrome,Cross Browser,我在我的浏览器中显示以下html(firefox可以工作,但chrome和safari不能)。下面在firefox中显示的内容按预期工作,但safari和chrome显示了一个蓝色问号,周围有一个方框 <html> <head> <title>test</title> </head> <body> <img src='pixel.php' /> </body> <

我在我的浏览器中显示以下html(firefox可以工作,但chrome和safari不能)。下面在firefox中显示的内容按预期工作,但safari和chrome显示了一个蓝色问号,周围有一个方框

<html>
  <head>
    <title>test</title>
  </head>
  <body>
    <img src='pixel.php' />
  </body>
</html>
该1x1t.gif文件与脚本存在于同一目录中,并且在firefox中一切正常-但是safari和chrome会显示一个蓝色问号


我需要做什么才能让safari和chrome按预期运行?

是路径问题。正在解析。

您可能希望切换到使用readfile()而不是fpassthru()。fpassthru将在将文件发送到客户端之前将其读入内存。如果大型文件超过脚本的内存限制,则此操作将失败。readfile()将自动以小块的形式发送文件。至于safari/chrome,试着保存蓝色?通过右键单击,查看结果。也许Firefox可以绕过PHP头,但Safari/Chrome不行。
// 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);