国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 浑源县| 凤翔县| 普陀区| 河曲县| 上饶市| 美姑县| 云霄县| 库车县| 确山县| 于都县| 塔城市| 芜湖县| 英德市| 葵青区| 扶绥县| 图们市| 北辰区| 连州市| 涞源县| 万宁市| 镇雄县| 温宿县| 伊通| 张北县| 林州市| 宁陵县| 德安县| 滁州市| 翁牛特旗| 凤冈县| 海口市| 高阳县| 胶南市| 同仁县| 平原县| 理塘县| 永春县| 七台河市| 大连市| 阿拉善左旗| 锦州市|