<?php
/*
@desc:php下载文件显示进度
@param file 待下载文件名
@param name 存储到本地文件名
*/
function downloadprogress($file,$name){
$dir = dirname($name);
if(!is_dir($dir)){
mkdir($dir,0755,true);
}
ob_start();
set_time_limit(0);
$fr = fopen ($file, "rb");
if ($fr) {
$content = file_get_contents($file);
$filesize = strlen($content);
$fw = fopen ($name, "wb");
$downlen=0;
$last = 0;
$diff = 0;
echo "[";
if ($fw) {
while(!feof($fr)) {
$data = fread($fr, 1024 * 8 );
$downlen += strlen($data);
fwrite($fw, $data, 1024 * 8 );
$percent = round($downlen/$filesize*100,2);
$diff += $percent - $last;
if($diff > 1){
echo "#";
$diff = 0;
}
$last = $percent;
ob_flush();
flush();
}
echo "#]done";
}
if ($fr) {
fclose($fr);
}
if ($fw) {
fclose($fw);
}
}
}
downloadprogress('2018.rar','aaa/01.rar');
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。