您好,登錄后才能下訂單哦!
<?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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。