2014-11-22 56 views
0

我有下一个脚本从服务器读取映像文件并将其返回给用户。 即使网络管理器中的所有内容都看起来不错,浏览器(包括chrome和FF)也无法正常显示图像,但标头和文件大小正确,并且文件本身在服务器上创建。php读取动态映像文件失败,需要想法

if (!file_exists($previewFileName)) { 
     //... here comes creating the image code, I had tested it and the image is there!!! 
    } 
    //http://stackoverflow.com/a/15271869/2992810 
    session_write_close(); 

    header("Content-Type: image/$ext"); 
    //set cache header 
    $seconds_to_cache = -1; //three month 
    $ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT"; 
    header("Expires: $ts"); 
    header("Pragma: nocache"); 
    header("Cache-Control: max-age=$seconds_to_cache"); 
    //return the file 
    echo file_get_contents($previewFileName); 
    die(); 

这里是响应heeaders:

HTTP/1.1 200 OK 
Date: Sat, 22 Nov 2014 16:02:42 GMT 
Server: Apache/2.4.9 (Win64) OpenSSL/1.0.1g PHP/5.5.12 
X-Powered-By: PHP/5.5.12 
P3P: CP="CAO PSA OUR" 
Expires: Sat, 22 Nov 2014 16:02:41 GMT 
Cache-Control: max-age=-1 
Pragma: nocache 
Set-Cookie: kdm_csrf_cookie=d1bd278e07c72a69659d3c97471001b5; expires=Sat, 22-Nov-2014 18:02:42 GMT; Max-Age=7200; path=/ 
X-Frame-Options: SAMEORIGIN 
Keep-Alive: timeout=5, max=98 
Connection: Keep-Alive 
Transfer-Encoding: chunked 
Content-Type: image/jpg 

的Chrome网络管理输出523KB文件大小。 但是,Chrome和FireFox都没有显示图像本身。

我想也许图像本身已经坏了,但是我直接从HD打开它,它工作的很好,所以我不知道是什么导致浏览器不能渲染图像。

任何线索或想法如何调试它进一步将不胜感激....

回答

0

的人谁在未来遇到的图像相关的错误。
请在阅读图像文件之前确认您没有在屏幕上打印任何内容。
我不小心打印了2个空白空间,导致图像读取失败!

该死!