Please help to see this php download MP4 file problem, the file download is not complete

Source: Internet
Author: User
Tags php download
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

  • Related Article

    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.