2014-11-22 32 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個空白空間,導致圖像讀取失敗!

該死!