<?php
 namespace Moto\Application\FileManager\InputFilter; use Zend; use Moto\Application\FileManager; use Moto\InputFilter\AbstractInputFilter; use Moto; class UploadFile extends AbstractInputFilter { protected $_name = 'fileManager.upload'; public function init() { $this->_addElementFile(); } protected function _addElementFile($path = '') { $filter = new Moto\Filter\RelativePath(); $path = Moto\System::getAbsolutePath('@userUploads/' . $filter->filter($path)); if(!is_dir($path) || !is_writable($path)) { throw new Moto\Exception(Moto\System\Exception::ERROR_BAD_REQUEST_MESSAGE, Moto\System\Exception::ERROR_BAD_REQUEST_CODE, array('MEDIALIBRARY.UPLOAD_FOLDER_NOT_EXISTS')); } $this->remove('file'); $info = Moto\Application\FileManager\Service::getInfo(); $this->add(array( 'name' => 'file', 'type' => 'Zend\InputFilter\FileInput', 'required' => true, 'filters' => array( array( 'name' => 'Moto\Application\FileManager\Filter\RenameUpload', 'options' => array( 'target' => $path, 'overwrite' => false, 'randomize' => true, 'use_upload_name' => true, ) ), ), 'validators' => array( array( 'name' => 'File\UploadFile', ), array( 'name' => 'File\Size', 'options' => array( 'max' => $info['upload_max_size'] ) ), array( 'name' => 'File\Extension', 'options' => array( 'extension' => $info['allowed_ext_list'] ) ) ), )); } public function setData($data) { if (!empty($data['path'])) { $this->_addElementFile($data['path']); } $result = parent::setData($data); return $result; } } 