Import Soul Wouldn’t it be nice if things just worked


Loading files with Internet Explorer

While constructing various websites i have slowly learned to hate Internet Explorer completely and in all its forms, from messing up the appearance of your site, to corrupting files up for download though PHP.

Since i had so much trouble with it i thought it would be worthwhile to post the solution to internet explorer corrupting some files that are loaded through PHP e.g.

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($path));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($path));

The simplest way i found to correct the problem was to comment (or remove) out the line declaring the length of the file

//header('Content-Length: ' . filesize($path));

The downside to this method is that for downloading large files, users wont know the total size of the file being downloaded, luckily for me the files been downloaded were small enough for this not to cause problems.

I hope that by writing this i manage to save somebody some time and frustration, leave a comment if you have any other fixes for internet explorers many problems.

Comments (0) Trackbacks (0)

No comments yet.

Leave a comment

No trackbacks yet.