March 25, 2012

internet explorer cannot download 704 from site

internet explorer cannot download 704 from site


This problem will mostly occur when you will test your script in old version(s) of IE. This article is continuity of previous article Download file problem due to version incompatibility of IE & Adobe Reader. In fact when i posted the previous problem with corrections so that was working fine with file downloading but story doesn’t end here. Our requirement was not only to download files but their format should be correct as well. Have you noticed that Content-Transfer-Encoding is binary in our script. There are other options as well. But i want discuss a little about change of binary code. Although, download script can be written in different scripting languages but if you are writing it in PHP so you can have this problem as well. Problem is about the PHP error occurred, either syntax error or any logical error. Once PHP occurred so your binary will be appended by that error notification. I experienced it when i checked that why files are not opening although downloaded correctly and in complete size. I would suggest you to check you files which you are downloading but couldn’t open them correctly. Right click on that file and open with notepad, you will see some PHP errors in that file appended as prefix or postfix depends upon occurrence. Anyways, lets talk about another header parameter is Content-Type which i suggested in my last post to be the same which we get from mime_content_type but when i reviewed my code so couldn’t get problem from this portion. Because octet/stream is fine for this purpose. What i found which lead my script towards working condition is ob_clean() and flush() functions. Here my findings matched which i already discussed above about appending content of the file, by these two functions we will clean whatever will be written before the binary of the file. Here is the refined script which is working in IE8 and old version(s) IE7.

header(‘Content-Type: application/octet-stream’);
header(‘Content-Disposition: attachment; filename=’.file_parts($filename,’name’));
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($filename));
ob_clean();
flush();
readfile($filename);
exit;

Please click on file_parts to view the helper function which i coded just to speed up the work. Although the resembling function is already available in PHP but with a little different flavors.

Last updated: March 19, 2014
Did it helped? 2 thoughts on “internet explorer cannot download 704 from site
  1. janef

    no comment except Great!

  2. about

    Thanks for your marvelous posting! I really enjoyed reading it, you happen to be a great author.
    I will be sure to bookmark your blog and will come back later in life.

    I want to encourage you to ultimately continue your great work, have a nice holiday weekend!

Comments are closed.