Skip to content

Commit

Permalink
Upload - Improve max filesize in bytes from ini - refs BT#19380
Browse files Browse the repository at this point in the history
  • Loading branch information
cfasanando committed Feb 21, 2022
1 parent 780e761 commit 1c91e11
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
29 changes: 29 additions & 0 deletions main/inc/lib/fileUpload.lib.php
Expand Up @@ -2177,3 +2177,32 @@ function add_all_documents_in_folder_to_database(
}
}
}

/**
* Get the uploax max filesize from ini php in bytes.
*
* @return int
*/
function getIniMaxFileSizeInBytes()
{
$maxSize = 0;
if (preg_match('/^([0-9]+)([a-zA-Z]*)$/', ini_get('upload_max_filesize'), $matches)) {
// see http://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
switch (strtoupper($matches['2'])) {
case 'G':
$maxSize = $matches['1'] * 1073741824;
break;
case 'M':
$maxSize = $matches['1'] * 1048576;
break;
case 'K':
$maxSize = $matches['1'] * 1024;
break;
default:
$maxSize = $matches['1'];
}
}
$maxSize = (int) $maxSize;

return $maxSize;
}
2 changes: 1 addition & 1 deletion main/inc/lib/formvalidator/Element/BigUpload.php
Expand Up @@ -25,7 +25,7 @@ public function toHtml()
{
$origin = $this->getAttribute('data-origin');
$id = $this->getAttribute('id');
$maxSize = ini_get('upload_max_filesize');
$maxSize = getIniMaxFileSizeInBytes();
$html = parent::toHtml();
$html .= '<div id="'.$id.'-bigUploadProgressBarContainer">
<div id="'.$id.'-bigUploadProgressBarFilled"></div>
Expand Down
3 changes: 1 addition & 2 deletions main/inc/lib/javascript/bigupload/inc/bigUpload.php
Expand Up @@ -18,7 +18,6 @@ class BigUpload
/**
* Max allowed filesize. This is for unsupported browsers and
* as an additional security check in case someone bypasses the js filesize check.
*
*/
private $maxSize;

Expand Down Expand Up @@ -51,7 +50,7 @@ public function __construct()
$tempDirectory = api_get_path(SYS_ARCHIVE_PATH);
$this->setTempDirectory($tempDirectory);
$this->setMainDirectory(self::MAIN_DIRECTORY);
$this->maxSize = ini_get('upload_max_filesize');
$this->maxSize = getIniMaxFileSizeInBytes();
}

/**
Expand Down

0 comments on commit 1c91e11

Please sign in to comment.