mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-02 13:02:24 +08:00
FileValidator->getSizeLimit: check also php's post_max_size
- return the lowerest of `post_max_size` or `upload_max_filesize` - Raised warning for misconfigured PHP close #8373
This commit is contained in:
committed by
Carsten Brandt
parent
0575a710c0
commit
a6fc02345e
@ -248,9 +248,10 @@ class FileValidator extends Validator
|
||||
|
||||
/**
|
||||
* Returns the maximum size allowed for uploaded files.
|
||||
* This is determined based on three factors:
|
||||
* 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]]
|
||||
*
|
||||
@ -258,7 +259,13 @@ class FileValidator extends Validator
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user