Created
June 21, 2016 11:09
-
-
Save s2ar/225e5352c74d9b565fc32177af14a5b8 to your computer and use it in GitHub Desktop.
Максимальный размер загружаемого файла
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
<?php | |
function convertPHPSizeToBytes($sSize) | |
{ | |
if ( is_numeric( $sSize) ) { | |
return $sSize; | |
} | |
$sSuffix = substr($sSize, -1); | |
$iValue = substr($sSize, 0, -1); | |
switch(strtoupper($sSuffix)){ | |
case 'P': | |
$iValue *= 1024; | |
case 'T': | |
$iValue *= 1024; | |
case 'G': | |
$iValue *= 1024; | |
case 'M': | |
$iValue *= 1024; | |
case 'K': | |
$iValue *= 1024; | |
break; | |
} | |
return $iValue; | |
} | |
function getMaximumFileUploadSize() | |
{ | |
return min(convertPHPSizeToBytes(ini_get('post_max_size')), convertPHPSizeToBytes(ini_get('upload_max_filesize'))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment