PHP get actual maximum upload size

前端 未结 6 467
Happy的楠姐
Happy的楠姐 2020-12-04 16:38

When using

ini_get(\"upload_max_filesize\");

it actually gives you the string specified in the php.ini file.

It is not good to use

6条回答
  •  时光取名叫无心
    2020-12-04 17:05

    Looks like it isn't possible.

    Because of this, I am going to continue using this code:

    function convertBytes( $value ) {
        if ( is_numeric( $value ) ) {
            return $value;
        } else {
            $value_length = strlen($value);
            $qty = substr( $value, 0, $value_length - 1 );
            $unit = strtolower( substr( $value, $value_length - 1 ) );
            switch ( $unit ) {
                case 'k':
                    $qty *= 1024;
                    break;
                case 'm':
                    $qty *= 1048576;
                    break;
                case 'g':
                    $qty *= 1073741824;
                    break;
            }
            return $qty;
        }
    }
    $maxFileSize = convertBytes(ini_get('upload_max_filesize'));
    

    Originally from this helpful php.net comment.

    STILL OPEN TO ACCEPT BETTER ANSWERS

提交回复
热议问题