Php file download code sharing compatible with Internet Explorer 6

Source: Internet
Author: User
This article mainly introduces php file download code sharing compatible with the IE 6 browser, solves the bug that files cannot be downloaded in ie6. if you need it, refer to ie6.

PS: There is no problem with running this code in the win System. Feng Ge can test it in person. if you are using linux or other systems, you need to test it on your own.

$ Filename = ". /". $ _ REQUEST ['name']; // Here is the specific path of Fengge, as long as $ filename is the complete path of the file to be downloaded. if (! Is_file ($ filename) {// check whether the file exists. die ('the downloaded file seems to be away with TM! ') ;}$ Filepath = str_replace (' \ ','/', realpath ($ filename); $ filesize = filesize ($ filepath ); $ filename = substr (strrchr ('/'. $ filepath, '/'), 1); $ extension = strtolower (substr (strrchr ($ filepath ,'. '), 1); // use this unless you want to find the mime type based on extension, file suffix format, not interpreted. $ mime = array ('application/octet-stream'); header ('content-Type :'. $ mime); header ('content-Disposition: attachment; fil Ename = "'. $ filename. '"'); header ('content-Transfer-Encoding: binary '); header ('content-Length :'. sprintf ('% d', $ filesize); header ('expires: 0'); // check for IE only headers. you know, IE detection. if (isset ($ _ SERVER ['http _ USER_AGENT ']) & (strpos ($ _ SERVER ['http _ USER_AGENT'], 'msi ')! = False) {header ('cache-Control: must-revalidate, post-check = 0, pre-check = 0'); header ('pragma: public ');} else {header ('pragma: no-cache');} $ handle = fopen ($ filepath, 'RB'); fpassthru ($ handle ); fclose ($ handle );

This code was found by Feng Ge from a foreign site and is available for test. you know the result from du Niang. therefore, I shared it on my blog and hoped it would be useful to everyone. if you forget the address of a foreign site, you cannot release it. finally, let's make a serious statement: this code is not written by me and is reprinted.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.