PHP file speed limit download code

Source: Internet
Author: User

<?PHPinclude("DBDA.class.php");$db=NewDbda ();$bs=$_server["Query_string"];//gets the arguments passed by the submission interface.$BSS=substr($bs, 3);//Intercept = the value behind$sql= "Select video from Shangpin where id= ' {$BSS}‘";//get the video file path$str=$db->strquery ($sql);$WJM=substr($str, 13);//intercepting file names$lj=substr($str, 0,13);//The folder path where the file is intercepted $file _name=$WJM;//file name//To solve problems that cannot be displayed in Chinese$file _name=Iconv("Utf-8", "gb2312",$file _name); $file _sub_path=$_server[' Document_root '].$lj;//gets the document root directory where the current run script resides$file _path=$file _sub_path.$file _name;//the path to which the complete file is to be spelled//$file = include pathif(file_exists($file _path))//determine if a file exists{    Header(' Content-description:file Transfer ');//The header function is submitted to the table header is some of the download specifications    Header(' Content-type:application/octet-stream '); Header(' Content-disposition:attachment; Filename= '.basename($file _path)); Header(' Content-transfer-encoding:binary '); Header(' expires:0 '); Header(' Cache-control:must-revalidate, post-check=0, pre-check=0 '); Header(' Pragma:public '); Header(' Content-length: '.filesize($file _path)); Ob_clean();//Ob_clean This function is used to discard the contents of the output buffer, if your site has a lot of generated files, you want to access the correct, you should always clear the buffer    Flush();//the difference between ob_flush () and flush (). The former is the release of data from the buffer of PHP, the latter is not buffered or released data sent to the browser. So when the buffers are present, we have to use both ob_flush () and flush ().         $file=fopen($file _path, "R");//opens the specified file, R represents read-only, and returns false if not found     while(!feof($file))//determine if there is    {        //send The current file part to the browser        Print fread($file,round(3000 * 1024));//Top Download speed 3MB//flush the content to the browser        Flush();//Pass to Browser//sleep one second        Sleep(1);//wait 1 seconds    }    fclose($file);//Close File        /*ReadFile ($file _path); You can also use this method to send out the table header directly output, but there is no speed limit exit;*/}

PHP file speed limit download code

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.