VERY STRANGE Image Size behavior (when PHP script sends image to browser)
Posted on 2003-11-24
I'm using a PHP Script to read a file from outside of the document root, and sends it to the browser.
The problem is that I.E. Does not correctly "understand" the size fo the image (when I right click and select properties it says "Not Specified".
I've tracked this down to the fact that I am calling session_start() before sending the image. As a result, the session cookie is sent to the browser before the image data and when this happens, i.e. doesn't correctly understand the image size (for some bizarr reason).
At any rate, if I simply comment out this line, the image works EXACTLY as though it's accessed directly (not through the script). The problem is that I need data from the session to determine which image to show.
So - my question is:
1) Is there any way to access the session data without sending a session cookie to the browser (just from my "picture" script).
2) Does anyone understand why this causes a problem in I.E. and is there any other way around it?
Thank you in advance for any help you can provide. The script is included below:
$filename = "/tmp/files/" . $_SESSION['filename'];
header("Content-Length: " . filesize($filename));
header("Content-Disposition: inline; filename=" . $_SESSION['filename']);
$fd = fopen ($filename, "r");
echo fread ($fd, filesize ($filename));
Again - All I have to do is just // session_start() and everything works PERFECTLY.