Limit each image to 1 MB.
UPLOAD_MAX_MB changes the limit, and UPLOAD_MAX_MB=none removes it.
This commit is contained in:
@@ -373,6 +373,24 @@ function upload_dir() {
|
||||
return $dir;
|
||||
}
|
||||
|
||||
/*
|
||||
* The largest image a story can have, in bytes, from UPLOAD_MAX_MB (1 MB
|
||||
* by default). NULL means no limit, which UPLOAD_MAX_MB=none gives.
|
||||
*/
|
||||
function upload_max_bytes() {
|
||||
$value = strtolower(trim((string)config('UPLOAD_MAX_MB', '')));
|
||||
if ($value === 'none')
|
||||
return NULL;
|
||||
if (!is_numeric($value) || (float)$value <= 0)
|
||||
$value = 1;
|
||||
return (int)((float)$value * 1024 * 1024);
|
||||
}
|
||||
|
||||
// The same in megabytes for a message, such as "1" or "2.5"
|
||||
function upload_max_mb() {
|
||||
return rtrim(rtrim(number_format(upload_max_bytes() / 1048576, 2, '.', ''), '0'), '.');
|
||||
}
|
||||
|
||||
function is_upload_name($name) {
|
||||
return is_string($name) && preg_match('/^[0-9a-f]{32}\z/', $name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user