Downloading File Issue in IE8

23 views
Skip to first unread message

kyle stanley

unread,
Aug 26, 2010, 4:02:06 PM8/26/10
to Professional PHP Developers
I have been on this issue for quite a while now. Basically I am
forcing a download through header(). It works in all browsers except
IE8. Final try is below:
header("Pragma: public"); // required
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // some day in the
past
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain
browsers

header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Content-Type: $ctype");
header("Content-Disposition: attachment; filename=
\"".basename($filename)."\";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".LOCAL_PATH."feed/Images/blah blah
blah /".@filesize($filename));

@readfile(LOCAL_PATH."feed/Images/blah blah blah /".$filename) or
die("File not found.");


I don't know if it is the readfile function or not. I am Clueless at
this point. Any suggestions would be superb.

Jack Timmons

unread,
Aug 26, 2010, 4:04:12 PM8/26/10
to professi...@googlegroups.com
On Thu, Aug 26, 2010 at 3:02 PM, kyle stanley <mitten...@gmail.com> wrote:
>  header("Content-Type: $ctype");

What's this set to?

--
Jack Timmons
@_Codeacula

kyle stanley

unread,
Aug 26, 2010, 4:06:38 PM8/26/10
to Professional PHP Developers
In this case "application/force-download"

On Aug 26, 4:04 pm, Jack Timmons <codeac...@codeacula.com> wrote:

Jack Timmons

unread,
Aug 26, 2010, 4:11:21 PM8/26/10
to professi...@googlegroups.com
On Thu, Aug 26, 2010 at 3:06 PM, kyle stanley <mitten...@gmail.com> wrote:
> In this case "application/force-download"

That looks hideous. Should you be using application/text or whatever
it actually is?

Second, why is the pragma required? HTML spec? Forgive me, I haven't
look up at headers in forever.

Here's exactly what I have in my download headers. It works for
everything I use (IE, Opera, Safari, Chrome, etc):
header("Content-Type: application/csv;");
header('Content-Disposition: attachment; filename="cards.csv"');

Switch CSV as applicable.

--
Jack Timmons
@_Codeacula

kyle stanley

unread,
Aug 26, 2010, 4:22:23 PM8/26/10
to Professional PHP Developers
It is still coming through as 0 bytes in IE. Wow. Originally this
was happening in Safari so I added the full path to the file in the
content-length header.
Ok. Here is my entire code. In this case $_POST['txtFileDownloaded']
= KL304.dwg

$filename = $_POST['txtFileDownloaded'];
$file_extension = strtolower(substr(strrchr($filename,"."),1));
switch ($file_extension) {
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpe": case "jpeg":
case "jpg": $ctype="image/jpg"; break;
case "dwg": $ctype="application/dwg"; break;
default: $ctype="application/force-download";
}

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // some day in the
past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Content-Type: $ctype");
header("Content-Disposition: attachment; filename=
\"".basename($filename)."\";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".LOCAL_PATH."feed/Images/blah blah
blah/".@filesize($filename));

if ($file_extension=='dwg') {
@readfile(LOCAL_PATH."feed/Images/blah blah blah/".$filename) or
die("File not found.");
}
else {
@readfile(URL_UPLOAD_PATH."$filename") or die("File not found.");
}

On Aug 26, 4:11 pm, Jack Timmons <codeac...@codeacula.com> wrote:

Jack Timmons

unread,
Aug 26, 2010, 4:27:16 PM8/26/10
to professi...@googlegroups.com
On Thu, Aug 26, 2010 at 3:22 PM, kyle stanley <mitten...@gmail.com> wrote:
> if ($file_extension=='dwg') {
>        @readfile(LOCAL_PATH."feed/Images/blah blah blah/".$filename) or
> die("File not found.");
> }
> else {
>        @readfile(URL_UPLOAD_PATH."$filename") or die("File not found.");
> }


Remove the @'s now. Are you getting any errors?

Sorry, but I'm just picking out baddies as I scan. I've gotten 80 bugs
in the past three days on a new system, and I'm trying to blaze
through them ;)

--
Jack Timmons
@_Codeacula

kyle stanley

unread,
Aug 26, 2010, 4:31:20 PM8/26/10
to Professional PHP Developers
Nope no errors. Still works in FF too. Could it be that I dont have
the application that runs the dwg file and IE recognizes that? If so,
that would be weird because the client, I would think, would have that
application.

On Aug 26, 4:27 pm, Jack Timmons <codeac...@codeacula.com> wrote:

Jack Timmons

unread,
Aug 26, 2010, 4:51:56 PM8/26/10
to professi...@googlegroups.com
On Thu, Aug 26, 2010 at 3:31 PM, kyle stanley <mitten...@gmail.com> wrote:
> Nope no errors.  Still works in FF too. Could it be that I dont have
> the application that runs the dwg file and IE recognizes that?  If so,
> that would be weird because the client, I would think, would have that
> application.

You've lost me. I did notice a comment about IE files on PHP.net
somewhere, I think if you google the application/force_download thing
you'll find it.

It seems to me there's some sort of voodoo going on here.

Is it because your content-length thing is messed up?

Should be:
header("Content-Length: ".@filesize(LOCAL_PATH."feed/Images/blah
blahblah/".$filename));

Or something like that.
--
Jack Timmons
@_Codeacula

Robert Gonzalez

unread,
Aug 26, 2010, 5:35:15 PM8/26/10
to professi...@googlegroups.com
Is this over HTTPS by any chance?

Jack Timmons
@_Codeacula

--
This group is managed and maintained by the development staff at 360 PSG. An enterprise application development company utilizing open-source technologies for todays small-to-medium size businesses.

For information or project assistance please visit :
http://www.360psg.com

You received this message because you are subscribed to the Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professi...@googlegroups.com
To unsubscribe from this group, send email to Professional-P...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/Professional-PHP

kyle stanley

unread,
Aug 27, 2010, 8:34:20 AM8/27/10
to Professional PHP Developers


On Aug 26, 5:35 pm, Robert Gonzalez
<robert.anthony.gonza...@gmail.com> wrote:
> Is this over HTTPS by any chance?

It is not.

bradleylamar

unread,
Aug 27, 2010, 11:11:56 AM8/27/10
to Professional PHP Developers
Cache-Control and Pragma headers prevent downloads in IE according to
Cody G here: http://us.php.net/manual/en/function.header.php
Haven't tested this one out myself.

Robert Gonzalez

unread,
Aug 27, 2010, 11:18:06 AM8/27/10
to professi...@googlegroups.com
That's why I was asking about SSL. I know for a fact that IE pukes on downloads over SSL that throw a Pragma: no-cache header so I had to remove that call from all of my forced downloads on my secure site. I also had to set the Expires header to 0.

kyle stanley

unread,
Aug 27, 2010, 11:50:21 AM8/27/10
to Professional PHP Developers
Thanks everyone for your input. I followed Cody G.'s comments
yesterday with no success. It is still coming through as 0 bytes. If
I figure this out I will post the solution.

Robert Gonzalez

unread,
Aug 27, 2010, 11:57:32 AM8/27/10
to professi...@googlegroups.com
Not that it would change anything, but I only set three headers on my force downloads:
Content-Type
Content-Disposition
Expires

In my case the Expires header is set to 0, not an actual date.


--
Reply all
Reply to author
Forward
0 new messages