<?php
namespace Website\Widgets\ContactForm\InputFilter; use Moto; class UploadFile extends Moto\InputFilter\AbstractInputFilter { public function init() { $path = Moto\System::getAbsolutePath('@tempUploads'); if (!is_dir($path)) { Moto\Util::createDir($path); } if (!is_dir($path) || !is_writable($path)) { throw new Moto\System\Exception(Moto\System\Exception::ERROR_BAD_REQUEST_MESSAGE, Moto\System\Exception::ERROR_BAD_REQUEST_CODE, array('file' => 'UPLOAD_FOLDER_NOT_EXISTS')); } $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'] ) ) ), )); } }