Please refer to the question of downloading MP4 files in PHP. the file download is incomplete.
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('test.mp4');
Google Chrome and IE are not complete.
Reply to discussion (solution)
Ob_clean ();
Flush ();
Readfile ($ file );
Ob_clean ();
Flush ();
Readfile ($ file );
This sentence exists.
No mime header added
Header ("Content-Transfer-Encoding: binary ");
Header ("Content-Length:". $ len );
Delete them.
No mime header added
MIME type? Canadian, IIS?
Header ("Content-Transfer-Encoding: binary ");
Header ("Content-Length:". $ len );
Delete them.
$ Len = filesize ($ file );
Header ("Content-Length:". $ len );
The preceding two sentences can be downloaded after deletion, but the file size is not counted. the download duration is not displayed for thunder and IE.
In the nginx + php environment, without the problem you mentioned, both ie and Thunder can download my files normally, but my files are flv. in this case, it can only indicate that the mime header is incorrect.
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/huoshan Shanglin Houyuan (yi group) [640x480]. flv '); only one file name is changed, but none of the other files have been changed.
In the nginx + php environment, without the problem you mentioned, both ie and Thunder can download my files normally, but my files are flv. in this case, it can only indicate that the mime header is incorrect.
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/huoshan Shanglin Houyuan (yi group) [640x480]. flv '); only one file name is changed, but none of the other files have been changed.
Is the file size displayed during IE and Thunder downloads?
I have never tested it. There should be a Content-Length header.
You can go to the ucenter documentation.
Blog viewing
Http://www.jb51.net/article/46440.htm