Please help to see this php download MP4 file on the issue, file download incomplete

Source: Internet
Author: User
Tags php download readfile
Please help to see this php download MP4 file problem, the file download is not complete
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 ("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
------Solution--------------------
Ob_clean ();
Flush ();
ReadFile ($file);
------Solution--------------------
No MIME header
------Solution--------------------
Header ("Content-transfer-encoding:binary");
Header ("Content-length:". $len);
These two, try to erase it.
------Solution--------------------
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.
  • 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.