function Dl_file ($file) { $len = filesize ($file); $filename = basename ($file); $file _extension = Strtolower (substr (STRRCHR ($filename, "."), 1); Switch ($file _extension) {case "mp4": $ctype = "Video/mp4"; Default: $ctype = "Application/force-download"; } Header ("Pragma:public"); Header ("expires:0"); Header ("Cache-control:must-revalidate, Post-check=0, pre-check=0"); Header ("Cache-control:public"); Header ("Content-description:file Transfer"); Header ("Content-type: $ctype"); $header = "content-disposition:attachment; Filename= ". $filename."; Header ($header); Header ("Content-transfer-encoding:binary"); Header ("Content-length:". $len); Ob_clean (); Flush (); ReadFile ($file); Exit;} Dl_file (' Test.mp4 ');
In Firefox, Google browser download normal, ie and thunder download file is not complete
Reply to discussion (solution)
Ob_clean ();
Flush ();
ReadFile ($file);
Ob_clean ();
Flush ();
ReadFile ($file);
That's what I'm saying!
No MIME header
Header ("Content-transfer-encoding:binary");
Header ("Content-length:". $len);
These two, try to erase it.
No MIME header
MIME type? Add that, IIS?
Header ("Content-transfer-encoding:binary");
Header ("Content-length:". $len);
These two, try to erase it.
$len = FileSize ($file);
Header ("Content-length:". $len);
The above 2 sentences can be downloaded after deletion, but no statistics file size, thunder and IE did not show the length of the download.
Nginx + PHP environment Without you said that the problem, ie and thunder can be normal download but my file is flv, so it can only indicate that the MIME header error
My code is as follows:
function Dl_file ($file) {
$len = FileSize ($file);
$filename = basename ($file);
$file _extension = Strtolower (substr (STRRCHR ($filename, "."), 1);
Switch ($file _extension) {
Case "mp4": $ctype = "Video/mp4"; Break
Default: $ctype = "Application/force-download";
}
Header ("Pragma:public");
Header ("expires:0");
Header ("Cache-control:must-revalidate, Post-check=0, pre-check=0");
Header ("Cache-control:public");
Header ("Content-description:file Transfer");
Header ("Content-type: $ctype");
$header = "content-disposition:attachment; Filename= ". $filename.";
Header ($header);
Header ("Content-transfer-encoding:binary");
Header ("Content-length:". $len);
Ob_clean ();
Flush ();
ReadFile ($file);
Exit
}
Dl_file (' http://res.805.com/videos/Huo Shan * kanbayashi hou yuan (Yi Qian billion group) [640x480].flv '); Just changed one file name, and nothing else has changed.
Nginx + PHP environment Without you said that the problem, ie and thunder can be normal download but my file is flv, so it can only indicate that the MIME header error
My code is as follows:
function Dl_file ($file) {
$len = FileSize ($file);
$filename = basename ($file);
$file _extension = Strtolower (substr (STRRCHR ($filename, "."), 1);
Switch ($file _extension) {
Case "mp4": $ctype = "Video/mp4"; Break
Default: $ctype = "Application/force-download";
}
Header ("Pragma:public");
Header ("expires:0");
Header ("Cache-control:must-revalidate, Post-check=0, pre-check=0");
Header ("Cache-control:public");
Header ("Content-description:file Transfer");
Header ("Content-type: $ctype");
$header = "content-disposition:attachment; Filename= ". $filename.";
Header ($header);
Header ("Content-transfer-encoding:binary");
Header ("Content-length:". $len);
Ob_clean ();
Flush ();
ReadFile ($file);
Exit
}
Dl_file (' http://res.805.com/videos/Huo Shan * kanbayashi hou yuan (Yi Qian billion group) [640x480].flv '); Just changed one file name, and nothing else has changed.
IE, Thunder download have display file size?
It's not tested. There's a "content-length head."
You can take a look at the Ucenter document.
Blog to see
Http://www.jb51.net/article/46440.htm