Train of thought: PHP read the file while reading the contents of the output to the browser
<?php
/**
* Created by Phpstorm.
* User:kung * date:15-10-21 * time
: PM 8:00 * *
set_time_limit (0); Large files are timed out when the read content is not finished, resulting in incomplete download files.
$fpath = ' The_file_path ';
$file _pathinfo = PathInfo ($fpath);
$file _name = $file _pathinfo[' basename '];
$file _extension = $file _pathinfo[' extension '];
$handle = fopen ($fpath, "RB");
if (FALSE = = $handle)
exit ("Failed to open the file");
$filesize = FileSize ($fpath);
Header ("CONTENT-TYPE:VIDEO/MPEG4"), or more different file types Set header output type
header ("Accept-ranges:bytes");
Header ("Accept-length:". $filesize);
Header ("content-disposition:attachment; Filename= ". $file _name);
$contents = ';
while (!feof ($handle)) {
$contents = fread ($handle, 8192);
echo $contents;
@ob_flush (); Release the data from the PHP buffer
flush (); Send the released data to the browser
fclose ($handle);
Exit