'); @readfile($file); When the popular IE setting “Reuse Window for Launching Shortcuts” is unchecked (access this setting in the Tools Menu > Internet Options > Advanced Tab) this script will output the file to the browser and open it in a different window if the user clicks the open button on the IE prompt. However, if this setting is checked, and browser windows are being re-used, then it will open up on top of the page where the link was clicked to access the script. If I instead set the html link target option to be “_blank”, the script will open up in a new window as expected if the “Reuse Window for Launching Shortcuts” is checked. But, if the setting is unchecked, the output XML file will open up in a new window and there will be another blank window also open that has the address of the script, in addition to our original window. This is far from ideal, and there is no way of knowing whether users have this option checked or not.
We are stuck with the distinct possibility of half of our visitors seeing either an annoying third blank window being opened or the script writing over their original window, depending on their “Reuse Window for Launching Shortcuts” setting. I wasted days trying to figure this out before I found the problem was easily solved.
I'm sure many of you out there have had similar problem when trying to use readfile to output images with a php file as the 'src' of a 'img' tag. It works fine 'as is' in Firefox but not in IE, Safari or g.Chrome. I found hundreds of results on google all saying things like 'there must be white space at the end of you code', 'you need this header or that header'. I couldn't believe what the solution was but here it is anyway! Remove the 'Width' and 'Height' attributes from your 'img' tag. If you are using the procedures outlined in this article to force sending a file to a user, you may find that the 'Content-Length' header is not being sent on some servers.
The reason this occurs is because some servers are setup by default to enable gzip compression, which sends an additional header for such operations. This additional header is 'Transfer-Encoding: chunked' which essentially overrides the 'Content-Length' header and forces a chunked download. Of course, this is not required if you are using the intelligent versions of readfile in this article. A missing Content-Length header implies the following: 1) Your browser will not show a progress bar on downloads because it doesn't know their length 2) If you output anything (e.g. White space) after the readfile function (by mistake), the browser will add that to the end of the download, resulting in corrupt data.