本文实例讲述了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编程从入门到精通全套视频教程
95Shop可以免费下载使用,是一款仿醉品商城网店系统,内置SEO优化,具有模块丰富、管理简洁直观,操作易用等特点,系统功能完整,运行速度较快,采用ASP.NET(C#)技术开发,配合SQL Serve2000数据库存储数据,运行环境为微软ASP.NET 2.0。95Shop官方网站定期开发新功能和维护升级。可以放心使用! 安装运行方法 1、下载软件压缩包; 2、将下载的软件压缩包解压缩,得到we
0
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号