PHP Code implementation control file download speed

Source: Internet
Author: User
This article mainly introduces the PHP control file download Speed method, the example analysis of PHP operation file skills, with a certain reference value, the need for friends can refer to the next

This article explains how PHP controls how fast files are downloaded. The implementation method is as follows:

<?php/* * Set here a limit of downloading rate (e.g. 10.20 kb/s) */$download _rate = 10.20; $download _file = ' download-file.zip ';  $target _file = ' target-file.zip '; if (file_exists ($download _file)) {/  * headers */  header (' last-modified: '. Gmdate (' d, D M Y h:i:s '). ' GMT ');  Header (' cache-control:private ');  Header (' Content-type:application/octet-stream ');  Header (' Content-length: '. FileSize ($download _file));  Header (' content-disposition:filename= '. $target _file);  /* Flush content *  /flush ();  /* Open File *  /$fh = @fopen ($download _file, ' R ');  while (!feof ($FH)) {/* Send only ' current '   of the file to browser *   /print fread ($fh, round ($download _rate * 1 024));   /* Flush the content to the browser *   /flush ();   /* Sleep for 1 sec *   /sleep (1);  }  /* Close File *  /@fclose ($FH);} else{die  (' Fatal error:the '. $download _file. ' File does not exist! ');}? >

Summary : The above is the entire content of this article, I hope to be able to help you learn.

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.