diff options
author | nachoparker <nacho@ownyourbits.com> | 2021-04-29 11:43:52 +0300 |
---|---|---|
committer | nachoparker <nacho@ownyourbits.com> | 2021-05-13 06:49:39 +0300 |
commit | 0ee3aa9186dd2a609b7a1fbaaabc77d02bc2c933 (patch) | |
tree | f468e038d61c73b2ca498bbe43b494a60198133b | |
parent | be30663c7a4b86a4b91bf39b3b2d49c87f53d95c (diff) |
ncp-web: fix backup download for big files in 32-bitv1.35.1
Signed-off-by: nachoparker <nacho@ownyourbits.com>
-rw-r--r-- | ncp-web/download.php | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/ncp-web/download.php b/ncp-web/download.php index 195ad818..7d694a27 100644 --- a/ncp-web/download.php +++ b/ncp-web/download.php @@ -27,7 +27,15 @@ if (!file_exists($file)) if (!is_readable($file)) die('NCP does not have read permissions on this file'); -$size = filesize($file); +function filesize_compat($file) +{ + if(PHP_INT_SIZE === 4) # workaround for 32-bit architectures + return trim(shell_exec("stat -c%s " . escapeshellarg($file))); + else + return filesize($file); +} + +$size = filesize_compat($file); $extension = pathinfo($file, PATHINFO_EXTENSION); if ($extension === "tar" ) @@ -41,7 +49,7 @@ ob_start(); ob_clean(); header('Content-Description: File Transfer'); header('Content-Type: ' . $mime_type); -header("Content-Transfer-Encoding: Binary"); +header("Content-Transfer-Encoding: Binary"); header("Content-disposition: attachment; filename=\"" . basename($file) . "\""); header('Content-Length: ' . $size); header('Expires: 0'); @@ -49,20 +57,21 @@ header('Cache-Control: must-revalidate'); header('Pragma: public'); $chunksize = 8 * (1024 * 1024); -if($size > $chunksize) + +if($size > $chunksize || PHP_INT_SIZE === 4) # always chunk for 32-bit architectures { $handle = fopen($file, 'rb') or die("Error opening file"); while (!feof($handle)) - { + { $buffer = fread($handle, $chunksize); echo $buffer; ob_flush(); flush(); - } + } - fclose($handle); + fclose($handle); } else readfile($file); |