How to determine the max file upload limit in php

前端 未结 6 1476
渐次进展
渐次进展 2020-12-14 03:55

How can the file upload size allowed by php settings be determined withing a php script?

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-14 04:24

    function return_bytes($val) 
    {
        $val = trim($val);
        $last = strtolower($val[strlen($val)-1]);
    
        switch($last) 
        {
            case 'g':
            $val *= 1024;
            case 'm':
            $val *= 1024;
            case 'k':
            $val *= 1024;
        }
    
        return $val;
    }
    
    function get_upload_max_filesize()
    {
        $max_upload = return_bytes(ini_get('upload_max_filesize'));
        $max_post = return_bytes(ini_get('post_max_size'));
        return min($max_upload, $max_post, $memory_limit);
    }
    

提交回复
热议问题