Правило для файлов + Рекурсивное создание папки

This commit is contained in:
Фёдор Подлеснов 2016-07-27 15:02:04 +03:00
parent 405192f96a
commit 233e90ce72
5 changed files with 72 additions and 11 deletions

View file

@ -0,0 +1,46 @@
<?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;
}
}