53 lines
1.3 KiB
PHP
53 lines
1.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Проверка формата времени
|
|
*/
|
|
namespace ctiso\Validator\Rule;
|
|
use ctiso\Validator\Rule\Abstract,
|
|
ctiso\Collection;
|
|
|
|
class IsFile extends Abstract
|
|
{
|
|
private $type = array();
|
|
private $maxsize = 1024;
|
|
|
|
function skipEmpty() {
|
|
return false;
|
|
}
|
|
|
|
function setSize($size) {
|
|
$this->maxsize = $size;
|
|
}
|
|
|
|
function setType(array $type) {
|
|
$this->type = $type;
|
|
}
|
|
|
|
public function isValid(Collection $container, $status = null)
|
|
{
|
|
if (!isset($_FILES[$this->field]) || $_FILES[$this->field]['error'] == UPLOAD_ERR_NO_FILE) {
|
|
$this->setErrorMsg('Файл не загружен');
|
|
return false;
|
|
}
|
|
|
|
if ($_FILES[$this->field]['error'] == UPLOAD_ERR_INI_SIZE) {
|
|
$this->setErrorMsg('Превышен размер файла');
|
|
return false;
|
|
}
|
|
|
|
$tmp = $_FILES[$this->field];
|
|
if (!in_array($tmp['type'], $this->type)) {
|
|
$this->setErrorMsg('Неверный формат файла');
|
|
return false;
|
|
}
|
|
|
|
if (((int)$tmp['size']) > $this->maxsize*1024) {
|
|
$this->setErrorMsg('Неверный размер файла');
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|