<?PHP/** * Created by Phpstorm. * User:kung * date:15-10-21 * Time: 8:00am in the afternoon*/ 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");//more different file types Set header output typeHeader("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;
PHP processing Large File download