php读取动态图像文件失败,需要创意

I am having the next script that reads image file from the server and return it to the user. For no reason the browsers (both chrome and FF) stopped showing the image even though everything looks fine in the network manager, the headers and the file size are correct, and the file itself created on the server.

    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();

and here is the response 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 network manager output 523KB as file size. but, no Chrome nor FireFox shows the image itself.

I thought maybe the image itself broken, but I had opened it straight from my HD and it works great so I have not a clue for what causing the browsers not to render the image.

Any clue or idea for how to debug it further more would be appreciated....

for anyone who encountered image related bugs in the future.
please verify that you are not printing anything to the screen before reading the image file.
I had printed accidentally 2 white spaces this causes the image reading to fail!

Damn!