Jump to content

Issue streaming files in IE


HardlyNoticable

Recommended Posts

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]
...
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.");
  }
}
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.