Skip to content

Commit

Permalink
Fixing download on big files
Browse files Browse the repository at this point in the history
  • Loading branch information
axeloz committed Jul 20, 2023
1 parent db843fe commit d7e91f6
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions app/Http/Controllers/BundleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,6 @@ public function downloadZip(Request $request, Bundle $bundle) {
// Getting file size
$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
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.Str::slug($bundle->title).'-'.time().'.zip'.'"');
Expand All @@ -111,16 +99,20 @@ public function downloadZip(Request $request, Bundle $bundle) {
header('Content-Length: '.$filesize);

// Downloading
$fh = fopen($filename, 'rb');
while (! feof($fh)) {
echo fread($fh, round($limit_rate));
flush();
if (config('sharing.download_limit_rate', false) !== false) {
$limit_rate = Upload::humanReadableToBytes(config('sharing.download_limit_rate'));

if ($limit_rate !== false) {
$fh = fopen($filename, 'rb');
while (! feof($fh)) {
echo fread($fh, round($limit_rate));
flush();
sleep(1);
}
fclose($filename);
}
else {
readfile($filename);
}
fclose($filename);
exit;

}
Expand Down

0 comments on commit d7e91f6

Please sign in to comment.