mirror of
https://github.com/axeloz/filesharing.git
synced 2025-05-06 10:03:55 +02:00
Fixing download on big files
This commit is contained in:
parent
db843fe7e0
commit
d7e91f67cc
1 changed files with 10 additions and 18 deletions
|
@ -91,18 +91,6 @@ class BundleController extends Controller
|
||||||
// Getting file size
|
// Getting file size
|
||||||
$filesize = filesize($filename);
|
$filesize = filesize($filename);
|
||||||
|
|
||||||
// Should we limit the download rate?
|
|
||||||
$limit_rate = config('sharing.download_limit_rate', false);
|
|
||||||
if ($limit_rate !== false) {
|
|
||||||
$limit_rate = Upload::humanReadableToBytes($limit_rate);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$limit_rate = $filesize;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Flushing everything
|
|
||||||
flush();
|
|
||||||
|
|
||||||
// Let's download now
|
// Let's download now
|
||||||
header('Content-Type: application/octet-stream');
|
header('Content-Type: application/octet-stream');
|
||||||
header('Content-Disposition: attachment; filename="'.Str::slug($bundle->title).'-'.time().'.zip'.'"');
|
header('Content-Disposition: attachment; filename="'.Str::slug($bundle->title).'-'.time().'.zip'.'"');
|
||||||
|
@ -111,16 +99,20 @@ class BundleController extends Controller
|
||||||
header('Content-Length: '.$filesize);
|
header('Content-Length: '.$filesize);
|
||||||
|
|
||||||
// Downloading
|
// Downloading
|
||||||
$fh = fopen($filename, 'rb');
|
if (config('sharing.download_limit_rate', false) !== false) {
|
||||||
while (! feof($fh)) {
|
$limit_rate = Upload::humanReadableToBytes(config('sharing.download_limit_rate'));
|
||||||
echo fread($fh, round($limit_rate));
|
|
||||||
flush();
|
|
||||||
|
|
||||||
if ($limit_rate !== false) {
|
$fh = fopen($filename, 'rb');
|
||||||
|
while (! feof($fh)) {
|
||||||
|
echo fread($fh, round($limit_rate));
|
||||||
|
flush();
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
fclose($filename);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
readfile($filename);
|
||||||
}
|
}
|
||||||
fclose($filename);
|
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue