Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downloading file - PHP warning loop "Permission denied" #879

Merged
merged 2 commits into from
Nov 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions tinyfilemanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3058,6 +3058,26 @@ function fm_download_file($fileLocation, $fileName, $chunkSize = 1024)
$contentType = implode(' ', $contentType);
}

$size = filesize($fileLocation);

if ($size == 0) {
fm_set_msg(lng('Zero byte file! Aborting download'), 'error');
fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));

return (false);
}

@ini_set('magic_quotes_runtime', 0);
$fp = fopen("$fileLocation", "rb");

if ($fp === false) {
fm_set_msg(lng('Cannot open file! Aborting download'), 'error');
fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));

return (false);

}

header("Cache-Control: public");
header("Content-Transfer-Encoding: binary\n");
header("Content-Type: $contentType");
Expand All @@ -3074,7 +3094,6 @@ function fm_download_file($fileLocation, $fileName, $chunkSize = 1024)

header("Accept-Ranges: bytes");
$range = 0;
$size = filesize($fileLocation);

if (isset($_SERVER['HTTP_RANGE'])) {
list($a, $range) = explode("=", $_SERVER['HTTP_RANGE']);
Expand All @@ -3090,12 +3109,6 @@ function fm_download_file($fileLocation, $fileName, $chunkSize = 1024)
header("Content-Length: " . $size);
}

if ($size == 0) {
die('Zero byte file! Aborting download');
}
@ini_set('magic_quotes_runtime', 0);
$fp = fopen("$fileLocation", "rb");

fseek($fp, $range);

while (!feof($fp) and (connection_status() == 0)) {
Expand Down