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.