Правило для файлов + Рекурсивное создание папки
This commit is contained in:
parent
405192f96a
commit
233e90ce72
5 changed files with 72 additions and 11 deletions
46
core/validator/rule/isfile.php
Normal file
46
core/validator/rule/isfile.php
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue