Streaming and IE
Posted: Tue Sep 05, 2006 7:06 am
feyd | Please use
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi There,
I'm building a web based upload/download app for my work in PHP. We have a lot of clients that we transfer files back and forth with and have some very specific processes that we wish to employ.
For downloading, I am streaming the file to the client's web browser (this way we can control access and do application level logging). However I am having a problem getting it to work properly in IE.
In IE, if the user saves the file, everything works fine. But if the user opens the file directly, the browser downloads the file and then doesn't open it. If the file is a PDF, the IE downloads the file, and acrobat reader starts, and then says it can't find the file. I suspect the file is downloading under one name (probably the correct one) and then the browser or reader is trying to open it under another name (probably the name of the php page that's streaming the file).
Has anyone here ever encountered this problem? I suspect it may have something to do with the header that I'm sending to the client's browser. I should mention that Firefox and Safari are not having any issues (only IE) and that I have tried this on multiple machines.
The following is the code I'm using for the actual download:Code: Select all
...
else // Usual download
{
header("HTTP/1.1 200 OK");
header("Content-Length: $filesize");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=$root_filename");
header("Content-Transfer-Encoding: binary");
if(file_exists($filepath) && $fh = fopen($filepath, "rb")){
while($buf = fread($fh, $bufsize))
print $buf;
fclose($fh);
set_activityrecord(0, "File downloaded - no error.");
}
else
{
header("HTTP/1.1 404 Not Found");
set_activityrecord(3, "File not found on download.");
}
}feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]