1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58:
<?php
namespace MvcCore\Ext\Forms\Validators\Files\Validations;
trait FileAndSize {
protected function validateFileAndSize (& $file) {
if (!is_uploaded_file($file->tmpFullPath))
return $this->handleUploadError(static::UPLOAD_ERR_NOT_POSTED);
if (!is_file($file->tmpFullPath))
return $this->handleUploadError(static::UPLOAD_ERR_NOT_FILE);
$fileSize = filesize($file->tmpFullPath);
if ($fileSize < 1)
return $this->handleUploadError(static::UPLOAD_ERR_EMPTY_FILE);
if ($fileSize === FALSE)
return $this->handleUploadError(static::UPLOAD_ERR_TOO_LARGE_FILE);
if ($this->minSize !== NULL && $fileSize < $this->minSize)
return $this->handleUploadError(
static::UPLOAD_ERR_MIN_SIZE, [
\MvcCore\Ext\Form::ConvertBytesIntoHumanForm($this->minSize)
]
);
if ($this->maxSize !== NULL && $fileSize > $this->maxSize)
return $this->handleUploadError(
static::UPLOAD_ERR_MAX_SIZE, [
\MvcCore\Ext\Form::ConvertBytesIntoHumanForm($this->maxSize)
]
);
$file->size = $fileSize;
return TRUE;
}
}