私が許可する最大ファイル速度でファイルをダウンロードできるようにするスクリプトを作成しましたが、10000kB/s のような「無制限」の速度を許可すると、ftell が奇妙に動作し、10000kBps の速度でダウンロードするように動作します。は真実ではなく、残り時間、現在のダウンロード速度などのデータベースで計算を行うことができません...
したがって、ブラウザはしばらくしてファイルをダウンロードしますが、データベースではすでに「ダウンロード済み」のようになっています。ユーザーがネットワークの速度でファイルをダウンロードできるように無制限の速度を設定し、データベースの値も...ftell();
に依存するものではなく、ネットワーク速度でカウントされ$download_rate;
ますか?
前もって感謝します!
<?php
while(!feof($fopen)) {
//echo fread($fopen, 4096);
$this->get_allowed_speed_limit($download_rate);
//$download_rate = 350;
print fread($fopen, round($download_rate * 1024));
sleep(1); //needed for download speed limit
if(connection_status() != 0 || connection_aborted()) {
$bytes_transferred = ftell($fopen);
if($bytes_transferred < $bytes) {
//CANCELLED
$this->download_unsuccessfull($file_name);
} else {
//CANCELLED (but gets executed only on strange networks like eduroam in CZE)
$this->download_unsuccessfull($file_name);}
flush();
die;
} else {
$progress = ftell($fopen) / $bytes * 100;
if($progress >= 100) {
//DONE
$this->download_successfull($file_name);
flush();
} else {
//DOWNLOADING
if(ftell($fopen) != 0) {
$bytes_transferred = ftell($fopen);
$time_end = microtime(true);
$time = $time_end - $time_start;
$dl_speed = floor(($bytes_transferred / $time) / 1000);
///////HERE THE CALCULATIONS ARE TOTALLY WRONG, BECAUSE IT ALL DEPENDS ON THE INPUT OF $download_rate;
mysqli_query($con, "UPDATE `download_meter` SET `current_speed` = '".mysqli_real_escape_string($con, $bytes_transferred)."'");
$this->update_active_downloads($file_name, $bytes_transferred, $dl_speed);
}
flush();
}
}
//Activate this for delay download.
//flush();
//sleep(1);
}
?>