开发者

How to download file as document in Internet Explorer? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 12 years ago. 开发者_开发百科

My file download as document is not working in IE. How can I write code in PHP to download the file correctly in Internet Explorer


The following is the code i have been using for the past three years and it is working fine. Just now i tested in all browsers IE6, IE7, IE8 and in all those it is working fine. The $fn is the full path of the file. and make sure that no other extra spaces or newlines are there anyway i have used ob_clean before flushing the file to the browser.

Better if you have no other html code sent above this... so use it seperately with no other content. else start the code with ob_start(); so at the line of ob_clean() there wont be any extra chars.

$filename = "$fn";
ob_clean();
header("Cache-Control: no-store");
header("Expires: 0");
header("Content-Type: application/octet-stream");
header("Content-disposition: attachment; filename=\"".basename($filename)."\"");
header("Content-Transfer-Encoding: binary");
header('Content-Length: '. filesize($filename));
readfile($filename);

I have a file management module where i upload files and the user can download it. If you still have issues or unable to make it work the just add few more lines of your problem and the people who ever sees would respond to that.

THE REASON I HAVE USED SOME MORE HEADERS IS TO MAKE SURE THAT IT WORKS BECAUSE INITIALLY I HAD PROBLEMS WITH IE 6.

for secure servers HTTPS replace the first two headers with this one.

header("Cache-Control:  maxage=1");
header("Pragma: public");

this way it is working for me.


Check to make sure that your header declaration is not in error. (With PHP you have to make sure that the Content type is declared correctly, and is the first line of the php file. http://php.net/manual/en/function.header.php)


Set correct HTTP header

<?php
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="downloaded.pdf"');
readfile('original.pdf');
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜