Last active
August 31, 2023 17:57
-
-
Save AlbinSoft/b26bf2fb8b06d77ecae82e24ba3b9472 to your computer and use it in GitHub Desktop.
PHP - Get the Maximum Upload Size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function file_upload_max_size_int() { | |
static $max_size = -1; | |
if($max_size<0) { | |
$post_max_size = intval(ini_get('post_max_size')); | |
$upload_max_size = intval(ini_get('upload_max_filesize')); | |
$max_size = min($post_max_size, $upload_max_size); | |
} | |
return $max_size; | |
} | |
function file_upload_max_size_str() { | |
static $max_size = -1; | |
if($max_size<0) { | |
$post_max_size = intval(ini_get('post_max_size')); | |
$upload_max_size = intval(ini_get('upload_max_filesize')); | |
$max_size = parse_size(min($post_max_size, $upload_max_size)); | |
} | |
return $max_size; | |
} | |
function parse_size($size) { | |
$unit = preg_replace('/[^bkmgtpezy]/i', '', $size); | |
$size = preg_replace('/[^0-9\.]/', '', $size); | |
if($unit) { | |
return round($size * pow(1024, stripos('bkmgtpezy', $unit[0]))); | |
} else { | |
return round($size); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment