yii\validators\FileValidator::getSizeLimit PHP Метод

getSizeLimit() публичный Метод

This is determined based on four factors: - 'upload_max_filesize' in php.ini - 'post_max_size' in php.ini - 'MAX_FILE_SIZE' hidden field - [[maxSize]]
public getSizeLimit ( ) : integer
Результат integer the size limit for uploaded files.
    public function getSizeLimit()
    {
        // Get the lowest between post_max_size and upload_max_filesize, log a warning if the first is < than the latter
        $limit = $this->sizeToBytes(ini_get('upload_max_filesize'));
        $postLimit = $this->sizeToBytes(ini_get('post_max_size'));
        if ($postLimit > 0 && $postLimit < $limit) {
            Yii::warning('PHP.ini\'s \'post_max_size\' is less than \'upload_max_filesize\'.', __METHOD__);
            $limit = $postLimit;
        }
        if ($this->maxSize !== null && $limit > 0 && $this->maxSize < $limit) {
            $limit = $this->maxSize;
        }
        if (isset($_POST['MAX_FILE_SIZE']) && $_POST['MAX_FILE_SIZE'] > 0 && $_POST['MAX_FILE_SIZE'] < $limit) {
            $limit = (int) $_POST['MAX_FILE_SIZE'];
        }
        return $limit;
    }

Usage Example

Пример #1
0
 public function testGetSizeLimit()
 {
     $size = min($this->sizeToBytes(ini_get('upload_max_filesize')),$this->sizeToBytes(ini_get('post_max_size')));
     $val = new FileValidator();
     $this->assertEquals($size, $val->getSizeLimit());
     $val->maxSize = $size + 1; // set and test if value is overridden
     $this->assertEquals($size, $val->getSizeLimit());
     $val->maxSize = abs($size - 1);
     $this->assertEquals($size - 1, $val->getSizeLimit());
     $_POST['MAX_FILE_SIZE'] = $size + 1;
     $this->assertEquals($size - 1, $val->getSizeLimit());
     $_POST['MAX_FILE_SIZE'] = abs($size - 2);
     $this->assertSame($_POST['MAX_FILE_SIZE'], $val->getSizeLimit());
 }