Регистр файлов
This commit is contained in:
parent
4fd0187ea6
commit
c8958cbee0
83 changed files with 25 additions and 53 deletions
49
src/Validator/Rule/IsFile.php
Normal file
49
src/Validator/Rule/IsFile.php
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Проверка формата времени
|
||||
*/
|
||||
class Validator_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;
|
||||
}
|
||||
|
||||
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 ($tmp['size'] > $this->maxsize*1024) {
|
||||
$this->setErrorMsg('Неверный размер файла');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue