46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
|
|
|
require_once 'abstract.php';
|
|
|
|
/**
|
|
* Проверка формата времени
|
|
*/
|
|
class Rule_IsFile extends Rule_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;
|
|
}
|
|
|
|
$tmp = $_FILES[$this->field];
|
|
if (!in_array($tmp['type'], $this->type)) {
|
|
$this->setErrorMsg('Неверный формат файла');
|
|
return false;
|
|
}
|
|
|
|
if ($tmp['size'] > $this->maxsize*1024) {
|
|
$this->setErrorMsg('Неверный размер файла');
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|