国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

php控制文件下載速度的方法

2024-05-04 23:33:20
字體:
供稿:網(wǎng)友

這篇文章主要介紹了php控制文件下載速度的方法,實例分析了php操作文件的技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了php控制文件下載速度的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:

 

 
  1. <?php 
  2. /* 
  3. * set here a limit of downloading rate (e.g. 10.20 Kb/s) 
  4. */ 
  5. $download_rate = 10.20; 
  6. $download_file = 'download-file.zip';  
  7. $target_file = 'target-file.zip'
  8. if(file_exists($download_file)){ 
  9. /* headers */ 
  10. header('Last-Modified:'.gmdate('D, d M Y H:i:s').'GMT'); 
  11. header('Cache-control: private'); 
  12. header('Content-Type: application/octet-stream'); 
  13. header('Content-Length: '.filesize($download_file)); 
  14. header('Content-Disposition: filename='.$target_file); 
  15. /* flush content */ 
  16. flush(); 
  17. /* open file */ 
  18. $fh = @fopen($download_file'r'); 
  19. while(!feof($fh)){ 
  20. /* send only current part of the file to browser */ 
  21. print fread($fhround($download_rate * 1024)); 
  22. /* flush the content to the browser */ 
  23. flush(); 
  24. /* sleep for 1 sec */ 
  25. sleep(1); 
  26. /* close file */ 
  27. @fclose($fh); 
  28. }else
  29. die('Fatal error: the '.$download_file.' file does not exist!'); 
  30. ?> 

希望本文所述對大家的php程序設(shè)計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 红原县| 五家渠市| 东海县| 项城市| 乌兰县| 宜城市| 中西区| 中超| 通河县| 晋城| 哈尔滨市| 铜梁县| 荔浦县| 申扎县| 大英县| 固始县| 额尔古纳市| 驻马店市| 和龙市| 漯河市| 徐汇区| 锦屏县| 抚州市| 达尔| 江西省| 黄龙县| 肇州县| 武陟县| 天柱县| 重庆市| 洱源县| 龙州县| 新兴县| 枝江市| 原平市| 茌平县| 珠海市| 若羌县| 广德县| 岳西县| 乳山市|