本文实例讲述了php控制文件下载速度的方法。分享给大家供大家参考。具体实现方法如下:
<?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 part of the file to browser */
print fread($fh, round($download_rate * 1024));
/* 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!');
}
?>希望本文所述对大家的php程序设计有所帮助。
更多相关教程请访问 php编程从入门到精通全套视频教程
微商城订单管理系统是一款基于php+mysql开发的php订单管理系统,她的特点如下: 产品特色: 支持商品规格、订单短信提醒,订单提交限制,站外调用, 批量发货/导出,数据报表,物流轨迹、免签支付等。 1、高度开源:除核心授权文件外全部开源,二开方便。 2、分布式部署:支持分布式部署、支持数据库读写分离。 3、第三方存储:支持附件腾讯云、阿里云、七牛云存储
22
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号