public function __construct()
 {
     $logo = new FileInput('logo');
     $logo->setRequired(false)->setAllowEmpty(false);
     $logo->getValidatorChain()->attach(new Size(array('messageTemplates' => array(Size::TOO_BIG => 'The file TOO_BIG', Size::TOO_SMALL => 'The file TOO_SMALL', Size::NOT_FOUND => 'The NOT_FOUND', NotEmpty::IS_EMPTY => 'Mail no debe ser vacía.'), 'options' => array('max' => 40000))));
     // Validator File Type //
     $mimeType = new MimeType();
     $mimeType->setMimeType(array('image/gif', 'image/jpg', 'image/jpeg', 'image/png'));
     $logo->getValidatorChain()->attach($mimeType);
     /** Move File to Uploads/product **/
     $nameFile = sprintf("%simg_%s", './public/assets/images/providers/', time());
     $rename = new RenameUpload($nameFile);
     //$rename->setTarget($nameFile);
     $rename->setUseUploadExtension(true);
     //$rename->setUseUploadName(true);
     $rename->setRandomize(true);
     $rename->setOverwrite(true);
     $logo->getFilterChain()->attach($rename);
     $this->add($logo);
     $this->add(array('name' => 'company', 'required' => true, 'validators' => array(array('name' => 'Alnum', 'options' => $this->opcionesAlnum)), 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))));
     $this->add(array('name' => 'company_id', 'required' => true, 'validators' => array(array('name' => 'Alnum', 'options' => $this->opcionesAlnum)), 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))));
     $this->add(array('name' => 'email', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'EmailAddress', 'options' => array('messages' => array('emailAddressInvalidFormat' => 'Email address format is not invalid'))), array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'Email address is required'))))));
     $this->add(array('name' => 'password', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'Password is required'))))));
     $this->add(array('name' => 'confirmarPassword', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'identical', 'options' => array('token' => 'password')))));
 }
Beispiel #2
0
 /**
  * @param FileInput $fileInput
  */
 private function addFileValidation(FileInput $fileInput)
 {
     if ($this->maxSize) {
         $fileInput->getValidatorChain()->attachByName('filesize', ['max' => $this->maxSize]);
     }
     if (count($this->extensions)) {
         $fileInput->getValidatorChain()->attachByName('fileextension', ['extension' => $this->extensions]);
     }
 }
 public function addInputFilter()
 {
     $inputFilter = new InputFilter\InputFilter();
     // File Input
     //$title=microtime(true)*20000;
     $fileInput = new InputFilter\FileInput('imagefile');
     $fileInput->setRequired(true);
     // You only need to define validators and filters
     // as if only one file was being uploaded. All files
     // will be run through the same validators and filters
     // automatically.
     //$validator = new \Zend\Validator\File\MimeType('image/gif,image/jpg,image/png');
     $fileInput->getValidatorChain()->attachByName('filesize', array('max' => 5480000))->attachByName('filemimetype', array('mimeType' => 'image/png'));
     // All files will be renamed, i.e.:
     //   ./data/tmpuploads/avatar_4b3403665fea6.png,
     //   ./data/tmpuploads/avatar_5c45147660fb7.png
     /* $fileInput->getFilterChain()->attachByName(
            'filerenameupload',
            array(
                'target'    => './data/tmpuploads/123/',
                'randomize' => true,
            )
        );*/
     $name = 1;
     if (!file_exists('eclip.tv/data/uploads/user/' . $name)) {
         mkdir('eclip.tv/data/uploads/user/' . $name, 0777, true);
     }
     $fileInput->getFilterChain()->attach(new \Zend\Filter\File\Rename("eclip.tv/data/uploads/user/" . $name . '/' . $title . ".png"));
     $inputFilter->add($fileInput);
     $this->setInputFilter($inputFilter);
 }
Beispiel #4
0
 public function __construct($uploadTmpPath, LabServiceInterface $labService, $attachmentSize)
 {
     $id = new Input('id');
     $id->setRequired(false)->getValidatorChain()->attach(new Validator\Digits());
     $name = new Input('name');
     $name->setRequired(true)->getFilterChain()->attach(new Filter\StringTrim());
     $name->getValidatorChain()->attach(new Validator\NotEmpty())->attach(new Validator\StringLength(['min' => 3]));
     $labTypeId = new Input('labtype_id');
     $labTypeId->setRequired(true);
     $labTypeId->getValidatorChain()->attach(new Validator\NotEmpty());
     $isNew = new Input('is_new');
     $isNew->setRequired(false)->getFilterChain()->attach(new Filter\ToInt());
     $responsibleId = new Input('responsible_id');
     $responsibleId->setRequired(false)->getValidatorChain()->attach(new Validator\Digits());
     $area = new Input('area');
     $area->setRequired(true)->getValidatorChain()->attach(new Validator\NotEmpty())->attach(new Validator\Digits());
     $lessons = new Input('lessons');
     $lessons->setRequired(false);
     $lessons->getValidatorChain()->attach(new Validator\NotEmpty());
     $attachment = new FileInput('attachment');
     $attachment->setRequired(false)->getFilterChain()->attach(new Filter\File\RenameUpload(['target' => $uploadTmpPath, 'randomize' => true]));
     $attachment->getValidatorChain()->attach(new Validator\File\UploadFile())->attach(new Validator\File\MimeType(['application/zip', 'application/x-rar-compressed', 'application/octet-stream', 'application/pdf', 'image/png', 'image/jpeg', 'image/gif', 'image/bmp', 'image/vnd.microsoft.icon', 'image/tiff', 'image/tiff', 'image/svg+xml', 'image/svg+xml', 'image/vnd.adobe.photoshop']))->attach(new Validator\File\Size(['max' => $attachmentSize]));
     $use_ext_program = new Input('use_ext_program');
     $use_ext_program->setRequired(false);
     $use_in_program = new Input('use_in_program');
     $use_in_program->setRequired(false);
     $has_network = new Input('has_network');
     $has_network->setRequired(false);
     $has_network->getValidatorChain()->attach(new Validator\NotEmpty())->attach(new Validator\InArray(['haystack' => $labService->getHasNetworkValues()]));
     $has_server = new Input('has_server');
     $has_server->setRequired(false);
     $has_server->getValidatorChain()->attach(new Validator\NotEmpty())->attach(new Validator\InArray(['haystack' => $labService->getHasServerValues()]));
     $this->inputFilter = new InputFilter();
     $this->inputFilter->add($id)->add($name)->add($labTypeId)->add($isNew)->add($responsibleId)->add($area)->add($lessons)->add($attachment)->add($use_in_program)->add($use_ext_program)->add($has_server)->add($has_network);
 }
 public function addInputFilter()
 {
     $inputFilter = new InputFilter\InputFilter();
     // File Input
     $title = sprintf("%.0f ", microtime(true) * 20000);
     $title = str_replace(' ', '', $title);
     //$title=(float) microtime(true)*20000;
     $fileInput = new InputFilter\FileInput('seriecode');
     $fileInput->setRequired(true);
     // You only need to define validators and filters
     // as if only one file was being uploaded. All files
     // will be run through the same validators and filters
     // automatically.
     $fileInput->getValidatorChain()->attachByName('filesize', array('max' => 500000000))->attachByName('filemimetype', array('mimeType' => 'video/mp4'));
     // All files will be renamed, i.e.:
     //   ./data/tmpuploads/avatar_4b3403665fea6.png,
     //   ./data/tmpuploads/avatar_5c45147660fb7.png
     $name = md5(date('ymd'));
     if (!file_exists('temp/data/tmpuploads/videos/' . $name)) {
         mkdir('temp/data/tmpuploads/videos/' . $name, 0777, true);
     }
     $fileInput->getFilterChain()->attachByName('filerenameupload', array('target' => './temp/data/tmpuploads/videos/' . $name . '/', 'randomize' => true));
     $inputFilter->add($fileInput);
     $this->setInputFilter($inputFilter);
 }
 public function uploadImageAction()
 {
     $this->checkAuth();
     $request = $this->getRequest();
     if ($request->isPost()) {
         // File upload input
         $file = new FileInput('avatar');
         // Special File Input type
         $file->getValidatorChain()->attach(new Validator\File\UploadFile());
         $file->getFilterChain()->attach(new Filter\File\RenameUpload(array('target' => './public/files/users/avatar/origin/', 'use_upload_name' => true, 'randomize' => true)));
         // Merge $_POST and $_FILES data together
         $request = new Request();
         $postData = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         $inputFilter = new InputFilter();
         $inputFilter->add($file)->setData($postData);
         if ($inputFilter->isValid()) {
             // FileInput validators are run, but not the filters...
             $data = $inputFilter->getValues();
             // This is when the FileInput filters are run.
             $avatar = basename($data['avatar']['tmp_name']);
             $this->databaseService->updateAvatar($this->user->id, $avatar);
             $this->user->avatar = $avatar;
         } else {
             // error
         }
     }
     return $this->redirect()->toRoute('profile');
 }
 public function __construct()
 {
     $translator = new \Zend\I18n\Translator\Translator();
     $translator->addTranslationFile('phparray', './module/Utenti/language/es.php');
     $translatorMvc = new \Zend\Mvc\I18n\Translator($translator);
     \Zend\Validator\AbstractValidator::setDefaultTranslator($translatorMvc);
     $nombre = new Input('nome');
     $nombre->setRequired(true);
     $nombre->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim');
     $nombre->getValidatorChain()->addValidator(new StringLength($this->opcionesStringLenght))->addValidator(new Alnum($this->opcionesAlnum));
     $this->add($nombre);
     $password = new Input('password');
     $password->setRequired(true);
     $password->getValidatorChain()->addValidator(new StringLength($this->opcionesStringLenght))->addValidator(new Alnum($this->opcionesAlnum));
     $this->add($password);
     $confirmarPassword = new Input('confirmarPassword');
     $confirmarPassword->setRequired(true);
     $confirmarPassword->getValidatorChain()->addValidator(new StringLength($this->opcionesStringLenght))->addValidator(new Alnum($this->opcionesAlnum))->addValidator(new Identical(array('token' => 'password', 'messages' => array('notSame' => 'I dati sono errati, riprova.'))));
     $this->add($confirmarPassword);
     $imagen = new FileInput('immagine');
     $imagen->setRequired(false);
     $imagen->getFilterChain()->attach(new RenameUpload(array('target' => './httpdocs/immagine/utenti/utenti_', 'use_upload_extension' => true, 'randomize' => true)));
     $imagen->getValidatorChain()->attach(new Size(array('max' => substr(ini_get('upload_max_filesize'), 0, -1) . 'MB')));
     /*
      $imagen->getValidatorChain()->attach(new MimeType(array(
      'mimeType' => 'image/png,image/x-png,image/gif,image/jpeg,image/pjpeg', 'enableHeaderCheck' => true
      )));
     */
     $this->add($imagen);
 }
 public function __construct(FilesOptions $options)
 {
     $input = new FileInput(self::FILE);
     $input->getValidatorChain()->attach(new Size(['max' => $options->getMaxSize()]));
     $input->getFilterChain()->attach(new RenameUpload(['overwrite' => false, 'use_upload_name' => true, 'target' => $options->getBasePath()]));
     $this->add($input);
 }
 /**
  * Class constructor.
  */
 public function __construct()
 {
     $this->add(['name' => 'item', 'required' => false, 'filters' => [['name' => 'StripTags'], ['name' => 'StringTrim']], 'validators' => [['name' => 'StringLength', 'options' => ['encoding' => 'UTF-8', 'min' => 5, 'max' => 15]]]]);
     $fileUpload = new FileInput('file');
     $fileUpload->setRequired(true);
     $fileUpload->getValidatorChain()->attachByName('File\\Size', ['min' => '20kB', 'max' => '8MB']);
     $this->add($fileUpload);
 }
 public function __construct()
 {
     // echo sprintf("%s/data/uploads/attachment.%s.txt", __DIR__ . '/../../../../..', time());die;
     $productImage = new FileInput('productImage');
     $productImage->setRequired(true)->setAllowEmpty(false);
     $productImage->getValidatorChain()->attach(new Size(array('messageTemplates' => array(Size::TOO_BIG => 'The file TOO_BIG', Size::TOO_SMALL => 'The file TOO_SMALL', Size::NOT_FOUND => 'The NOT_FOUND'), 'options' => array('max' => 40000))));
     // Validator File Type //
     $mimeType = new MimeType();
     $mimeType->setMimeType(array('image/gif', 'image/jpg', 'image/jpeg', 'image/png'));
     $productImage->getValidatorChain()->attach($mimeType);
     /** Move File to Uploads/product **/
     $nameFile = sprintf("%simg_%s", './public/assets/images/products/catalog/', time());
     $rename = new RenameUpload($nameFile);
     //$rename->setTarget($nameFile);
     $rename->setUseUploadExtension(true);
     //$rename->setUseUploadName(true);
     $rename->setRandomize(true);
     $rename->setOverwrite(true);
     $productImage->getFilterChain()->attach($rename);
     $this->add($productImage);
 }
Beispiel #11
0
 public function createInputFilter()
 {
     $inputFilter = new InputFilter\InputFilter();
     // File Input
     $file = new InputFilter\FileInput('file');
     $file->setRequired(true);
     $file->getFilterChain()->attachByName('filerenameupload', ['target' => DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_UPLOADS_ROOT . DirectoryStructure::FS_UPLOADS_TMP . 'attachment', 'overwrite' => true, 'randomize' => true, 'use_upload_name' => true]);
     // Allowed extensions
     $file->getValidatorChain()->attachByName('fileextension', ['doc', 'docx', 'xls', 'xlsx', 'pdf', 'csv', 'png', 'jpg', 'gif', 'ods', 'odt', 'ott', 'txt', 'zip', 'rar', '7z', 'tar']);
     $inputFilter->add($file);
     return $inputFilter;
 }
Beispiel #12
0
 public function createInputFilter()
 {
     $inputFilter = new InputFilter\InputFilter();
     // File Input
     $file = new InputFilter\FileInput('file');
     $file->setRequired(true);
     $file->getFilterChain()->attachByName('filerenameupload', ['target' => DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_IMAGES_ROOT . DirectoryStructure::FS_IMAGES_TEMP_PATH, 'overwrite' => true, 'randomize' => true, 'use_upload_name' => true]);
     // Allowed extensions
     $file->getValidatorChain()->attachByName('fileextension', ['png', 'jpg', 'gif']);
     $inputFilter->add($file);
     return $inputFilter;
 }
 public function __construct()
 {
     // Validações do titulo
     $titulo = new Input('titulo');
     $titulo->setRequired(true)->getFilterChain()->attach(new StringTrim())->attach(new StripTags());
     $titulo->getValidatorChain()->attach(new NotEmpty());
     // Validação do campo midia
     $file = new FileInput('midia');
     $file->setRequired(false);
     $file->getFilterChain()->attach(new RenameUpload(array("target" => \Base\Constant\Src::UPLOAD_PATH . \Base\Constant\Src::LIVRE_PARA_CRIAR, "randomize" => false, "overwrite" => true, "use_upload_name" => true)));
     $file->getValidatorChain()->attach(new Size(\Base\Constant\Upload::LIVRE_PARA_CRIAR_SIZE))->attach(new ImageSize(array('minWidth' => \Base\Constant\Upload::LIVRE_PARA_CRIAR_WIDTH, 'minHeight' => \Base\Constant\Upload::LIVRE_PARA_CRIAR_HEIGTH, 'maxWidth' => \Base\Constant\Upload::LIVRE_PARA_CRIAR_WIDTH, 'maxHeight' => \Base\Constant\Upload::LIVRE_PARA_CRIAR_HEIGTH)))->attach(new MimeType(array('image/gif', 'image/jpeg', 'image/png', 'image/x-png', 'enableHeaderCheck' => true)));
     //** Adicionando filtros **//
     $this->add($titulo)->add($file);
 }
Beispiel #14
0
 public function __construct()
 {
     // echo sprintf("%s/data/uploads/attachment.%s.txt", __DIR__ . '/../../../../..', time());die;
     $productImage = new FileInput('productImage');
     $productImage->setRequired(false)->setAllowEmpty(false);
     $productImage->getValidatorChain()->attach(new Size(array('messageTemplates' => array(Size::TOO_BIG => 'The file TOO_BIG', Size::TOO_SMALL => 'The file TOO_SMALL', Size::NOT_FOUND => 'The NOT_FOUND', NotEmpty::IS_EMPTY => 'Mail no debe ser vacía.'), 'options' => array('max' => 40000))));
     // Validator File Type //
     $mimeType = new MimeType();
     $mimeType->setMimeType(array('image/gif', 'image/jpg', 'image/jpeg', 'image/png'));
     $productImage->getValidatorChain()->attach($mimeType);
     /** Move File to Uploads/product **/
     $nameFile = sprintf("%simg_%s", './public/assets/images/products/catalog/', time());
     $rename = new RenameUpload($nameFile);
     //$rename->setTarget($nameFile);
     $rename->setUseUploadExtension(true);
     //$rename->setUseUploadName(true);
     $rename->setRandomize(true);
     $rename->setOverwrite(true);
     $productImage->getFilterChain()->attach($rename);
     $this->add($productImage);
     $this->add(array('name' => 'productName', 'required' => true, 'validators' => array(array('name' => 'Alnum', 'options' => $this->opcionesAlnum)), 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))));
     $this->add(array('name' => 'productDescription', 'required' => true, 'validators' => array(array('name' => 'not_empty')), 'filters' => $this->filterGeneric));
     $this->add(array('name' => 'productModel', 'required' => true, 'validators' => array(array('name' => 'Alnum', 'options' => $this->opcionesAlnum2))));
     $this->add(array('name' => 'productPrice', 'required' => true, 'validators' => array(array('name' => 'float', 'options' => array('locale' => 'en_US')), array('name' => 'stringLength', 'options' => array('min' => 1, 'max' => 10))), 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))));
     //         $productQuantity = new Input('productQuantity');
     //         $productQuantity->setAllowEmpty(true);
     //         $productQuantity->getValidatorChain()
     //             ->attach(new Digits());
     //         $this->add($productQuantity);
     $this->add(array('name' => 'productMinimun', 'required' => false, 'validators' => array(array('name' => 'Digits'))));
     // Meta-Data Form
     $this->add(array('name' => 'productMetaTittle', 'required' => true, 'validators' => array(array('name' => 'Alnum', 'options' => $this->opcionesAlnum)), 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))));
     $this->add(array('name' => 'productSeoUrl', 'required' => true, 'validators' => array(array('name' => 'not_empty')), 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'), array('name' => 'StringToLower'))));
     $this->add(array('name' => 'productMetaDescription', 'continue_if_empty' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))));
     $this->add(array('name' => 'productMetaKeywords', 'continue_if_empty' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))));
 }
 public function getInputFilter($userId = 0, $userName = "")
 {
     if (!$this->inputFilter) {
         $filter = new InputFilter();
         $filter->add(array('name' => 'userId', 'required' => true, 'filters' => array(array('name' => 'Int'))));
         $filter->add(array('name' => 'userName', 'required' => true, 'validators' => array(array('name' => 'StringLength', 'options' => array('max' => 200, 'min' => 1, 'encoding' => 'UTF-8')), array('name' => 'Db\\NoRecordExists', 'options' => array('table' => 'tbl_user', 'field' => 'userName', 'adapter' => $this->dbAdapter, 'exclude' => array('field' => 'userId', 'value' => $userId), 'message' => 'This user name is already exist.')))));
         $filter->add(array('name' => 'password', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('min' => 4, 'max' => 50)))));
         $filter->add(array('name' => 'confirmPassword', 'required' => true, 'validators' => array(array('name' => 'Identical', 'options' => array('token' => 'password')))));
         $fileInput = new FileInput('image');
         $fileInput->setRequired(false);
         $fileInput->getValidatorChain()->attachByName('filesize', array('max' => 204800))->attachByName('fileimagesize', array('maxWidth' => 256, 'maxHeight' => 256))->attach(new IsImage());
         //->attachByName('filemimetype', array('mimetype' => ''))
         $fileInput->getFilterChain()->attachByName('filerenameupload', array('target' => sprintf('./data/uploads/avatar/%s', $userName), 'use_upload_extension' => true, 'overwrite' => true));
         $filter->add($fileInput);
         $this->inputFilter = $filter;
     }
     return $this->inputFilter;
 }
 public function addInputFilter()
 {
     $inputFilter = new InputFilter\InputFilter();
     // File Input
     $fileInput = new InputFilter\FileInput('image-file');
     $fileInput->setRequired(true);
     // You only need to define validators and filters
     // as if only one file was being uploaded. All files
     // will be run through the same validators and filters
     // automatically.
     $fileInput->getValidatorChain()->attachByName('filesize', array('max' => 204800))->attachByName('filemimetype', array('mimeType' => 'image/png,image/x-png'))->attachByName('fileimagesize', array('maxWidth' => 100, 'maxHeight' => 100));
     // All files will be renamed, i.e.:
     //   ./data/tmpuploads/avatar_4b3403665fea6.png,
     //   ./data/tmpuploads/avatar_5c45147660fb7.png
     $fileInput->getFilterChain()->attachByName('filerenameupload', array('target' => './data/tmpuploads/avatar.png', 'randomize' => true));
     $inputFilter->add($fileInput);
     $this->setInputFilter($inputFilter);
 }
 public function __construct()
 {
     $translator = new \Zend\I18n\Translator\Translator();
     $translator->addTranslationFile('phparray', './module/Contenuti/language/es.php');
     $translatorMvc = new \Zend\Mvc\I18n\Translator($translator);
     \Zend\Validator\AbstractValidator::setDefaultTranslator($translatorMvc);
     $titolo = new Input('titolo');
     $titolo->setRequired(true);
     $titolo->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim');
     $titolo->getValidatorChain()->addValidator(new StringLength($this->opcionesStringLenght))->addValidator(new Alnum($this->opcionesAlnum));
     $this->add($titolo);
     $this->add(array('name' => 'posterlab', 'required' => true, 'validators' => array(array('name' => 'Int'))));
     $this->add(array('name' => 'tipo', 'required' => true, 'validators' => array(array('name' => 'Int'))));
     $background = new FileInput('background');
     $background->setRequired(true);
     $background->getFilterChain()->attach(new RenameUpload(array('target' => './httpdocs/immagine/contenuto/contenuto_', 'use_upload_extension' => true, 'randomize' => true)));
     $background->getValidatorChain()->attach(new Size(array('max' => substr(ini_get('upload_max_filesize'), 0, -1) . 'MB')));
     $this->add($background);
 }
 public function getInputFilter()
 {
     if (!$this->inputFilter) {
         $inputFilter = new InputFilter();
         $inputFilter->add(array('name' => 'news_id', 'required' => true, 'filters' => array(array('name' => 'Int'))));
         $inputFilter->add(array('name' => 'title', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8', 'min' => 1, 'max' => 255)))));
         $fileInput = new FileInput('photo');
         $fileInput->setRequired(true);
         /**
          * You only need to define validators and filters as if only one file was being uploaded. All files
          * will be run through the same validators and filters automatically.
          */
         $fileInput->getValidatorChain()->attachByName('filesize', array('max' => 2004800))->attachByName('filemimetype', array('mimeType' => 'image/png,image/x-png,image/jpeg,image/jpg'))->attachByName('fileimagesize', array('maxWidth' => 6000, 'maxHeight' => 6000));
         $inputFilter->add($fileInput);
         $inputFilter->add(array('name' => 'highlight', 'required' => true, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8', 'min' => 100)))));
         $inputFilter->add(array('name' => 'text', 'required' => true, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8', 'min' => 100)))));
         $this->inputFilter = $inputFilter;
     }
     return $this->inputFilter;
 }
Beispiel #19
0
 public function testMerge()
 {
     $value = array('tmp_name' => 'bar');
     $input = new FileInput('foo');
     $input->setAutoPrependUploadValidator(false);
     $input->setValue($value);
     $filter = new Filter\StringTrim();
     $input->getFilterChain()->attach($filter);
     $validator = new Validator\Digits();
     $input->getValidatorChain()->attach($validator);
     $input2 = new FileInput('bar');
     $input2->merge($input);
     $validatorChain = $input->getValidatorChain();
     $filterChain = $input->getFilterChain();
     $this->assertFalse($input2->getAutoPrependUploadValidator());
     $this->assertEquals($value, $input2->getRawValue());
     $this->assertEquals(1, $validatorChain->count());
     $this->assertEquals(1, $filterChain->count());
     $validators = $validatorChain->getValidators();
     $this->assertInstanceOf('Zend\\Validator\\Digits', $validators[0]['instance']);
     $filters = $filterChain->getFilters()->toArray();
     $this->assertInstanceOf('Zend\\Filter\\StringTrim', $filters[0]);
 }
    public function testValidationSkipsFileInputsMarkedNotRequiredWhenNoFileDataIsPresent()
    {
        $filter = new InputFilter();

        $foo   = new FileInput();
        $foo->getValidatorChain()->attach(new Validator\File\UploadFile());
        $foo->setRequired(false);

        $filter->add($foo, 'foo');

        $data = array(
            'foo' => array(
                'tmp_name' => '/tmp/barfile',
                'name'     => 'barfile',
                'type'     => 'text',
                'size'     => 0,
                'error'    => 4,  // UPLOAD_ERR_NO_FILE
            )
        );
        $filter->setData($data);
        $this->assertTrue($filter->isValid());

        // Negative test
        $foo->setRequired(true);
        $filter->setData($data);
        $this->assertFalse($filter->isValid());
    }
Beispiel #21
0
 /**
  * @return \Zend\InputFilter\InputFilter|\Zend\InputFilter\InputFilterInterface
  */
 public function getInputFilter()
 {
     if (!$this->inputFilter) {
         $inputFilter = new InputFilter();
         $factory = new InputFactory();
         $inputFilter->add($factory->createInput(['name' => 'dateApproved', 'required' => false]));
         $inputFilter->add($factory->createInput(['name' => 'dateSigned', 'required' => false]));
         $inputFilter->add($factory->createInput(['name' => 'branch', 'required' => false]));
         $inputFilter->add($factory->createInput(['name' => 'contact', 'required' => false]));
         $inputFilter->add($factory->createInput(['name' => 'organisation', 'required' => false]));
         $inputFilter->add($factory->createInput(['name' => 'program', 'required' => false]));
         $fileUpload = new FileInput('file');
         $fileUpload->setRequired(true);
         $fileUpload->getValidatorChain()->attachByName('File\\Size', ['min' => '20kB', 'max' => '8MB']);
         $inputFilter->add($fileUpload);
         $this->inputFilter = $inputFilter;
     }
     return $this->inputFilter;
 }
 public function addfileAction()
 {
     $this->checkAuth();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $file_attach = new FileAttachment();
         $file_attach->user_create = $this->auth->getIdentity()->id;
         $file_attach->date_create = date('Y-m-d H:i:s');
         $file_attach->last_date = $file_attach->date_create;
         $file_attach->last_user = $this->auth->getIdentity()->id;
         // info pay
         $file_attach->task_id = $request->getPost('task_id');
         $file_attach->permission_option = $request->getPost('permission_option');
         if ($this->isLevel2() != true) {
             $permission = $this->databaseService->getPermissionUser($file_attach->task_id, $file_attach->user_create);
             if ($permission == Config::FILE_PERMISSION_ERROR) {
                 return new JsonModel(array());
             }
             if ($permission == Config::FILE_PERMISSION_CUSTUMER) {
                 $file_attach->permission_option = Config::FILE_PERMISSION_CUSTUMER;
             }
             if ($permission == Config::FILE_PERMISSION_PROVIDER) {
                 $file_attach->permission_option = Config::FILE_PERMISSION_PROVIDER;
             }
         }
         // File upload input
         $file = new FileInput('file_name');
         // Special File Input type
         $file->getValidatorChain()->attach(new Validator\File\UploadFile());
         $file->getFilterChain()->attach(new Filter\File\RenameUpload(array('target' => '.' . Config::FILE_ATTACHMENT_PATH . $file_attach->task_id, 'use_upload_name' => true, 'randomize' => true)));
         if (!file_exists('.' . Config::FILE_ATTACHMENT_PATH . $file_attach->task_id)) {
             mkdir('.' . Config::FILE_ATTACHMENT_PATH . $file_attach->task_id, 0700, true);
         }
         // Merge $_POST and $_FILES data together
         $request = new Request();
         $postData = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         $inputFilter = new InputFilter();
         $inputFilter->add($file)->setData($postData);
         if ($inputFilter->isValid()) {
             // FileInput validators are run, but not the filters...
             $data = $inputFilter->getValues();
             // This is when the FileInput filters are run.
             $file_attach->real_name = basename($data['file_name']['tmp_name']);
             $file_attach->file_name = basename($data['file_name']['name']);
             $result = $this->databaseService->addFileAttachment($file_attach);
             $file_attach->id = $result->getGeneratedValue();
             $this->databaseService->addFileLog($this->auth->getIdentity()->id, $file_attach, Config::PAY_INFO_COMMON);
         }
     }
     return new JsonModel(array());
 }
Beispiel #23
0
 /**
  * @return \Zend\InputFilter\InputFilter|\Zend\InputFilter\InputFilterInterface
  */
 public function getInputFilter()
 {
     if (!$this->inputFilter) {
         $inputFilter = new InputFilter();
         $factory = new InputFactory();
         $inputFilter->add($factory->createInput(['name' => 'document', 'required' => false, 'filters' => [['name' => 'StripTags'], ['name' => 'StringTrim']], 'validators' => [['name' => 'StringLength', 'options' => ['encoding' => 'UTF-8', 'min' => 5, 'max' => 100]]]]));
         $inputFilter->add($factory->createInput(['name' => 'type', 'required' => true]));
         /*
          * Contact is not strictly needed in the form element as they will be added later
          */
         $inputFilter->add($factory->createInput(['name' => 'contact', 'required' => false]));
         /*
          * Project is not strictly needed in the form element as they will be added later
          */
         $inputFilter->add($factory->createInput(['name' => 'project', 'required' => false]));
         $fileUpload = new FileInput('file');
         $fileUpload->setRequired(true);
         $fileUpload->getValidatorChain()->attachByName('File\\Size', ['min' => '20kB', 'max' => '64MB']);
         $inputFilter->add($fileUpload);
         $this->inputFilter = $inputFilter;
     }
     return $this->inputFilter;
 }
 public function getInputFilter($proposalId = 0, $code = "")
 {
     if (!$this->inputFilter) {
         $filter = new InputFilter();
         $filter->add(array('name' => 'proposalId', 'required' => true, 'filters' => array(array('name' => 'Int'))));
         $filter->add(array('name' => 'code', 'required' => true, 'validators' => array(array('name' => 'StringLength', 'options' => array('max' => 50, 'min' => 1, 'encoding' => 'UTF-8')), array('name' => 'Db\\NoRecordExists', 'options' => array('table' => 'tbl_cr_proposal', 'field' => 'code', 'adapter' => $this->dbAdapter, 'exclude' => array('field' => 'proposalId', 'value' => $proposalId), 'message' => 'This proposal code is already exists.')))));
         $filter->add(array('name' => 'name', 'required' => true, 'validators' => array(array('name' => 'StringLength', 'options' => array('max' => 255, 'min' => 1, 'encoding' => 'UTF-8')))));
         $filter->add(array('name' => 'amount', 'required' => true));
         $filter->add(array('name' => 'proposalDate', 'required' => true));
         $filter->add(array('name' => 'notes', 'required' => false));
         $filter->add(array('name' => 'group_code', 'required' => false));
         $fileInput = new FileInput('proposalFile');
         $fileInput->setRequired(false);
         $fileInput->getValidatorChain()->attach(new Extension(array('doc', 'docx', 'pdf')))->attachByName('filesize', array('max' => '50MB'));
         $fileInput->getFilterChain()->attachByName('filerenameupload', array('target' => sprintf('./data/uploads/proposal/%s', $code), 'use_upload_extension' => true, 'overwrite' => true));
         $filter->add($fileInput);
         $this->inputFilter = $filter;
     }
     return $this->inputFilter;
 }
Beispiel #25
0
 /**
  * @return \Zend\InputFilter\InputFilter|\Zend\InputFilter\InputFilterInterface
  */
 public function getInputFilter()
 {
     if (!$this->inputFilter) {
         $inputFilter = new InputFilter();
         $factory = new InputFactory();
         $inputFilter->add($factory->createInput(['name' => 'document', 'required' => false, 'filters' => [['name' => 'StripTags'], ['name' => 'StringTrim']], 'validators' => [['name' => 'StringLength', 'options' => ['encoding' => 'UTF-8', 'min' => 5, 'max' => 100]]]]));
         $inputFilter->add($factory->createInput(['name' => 'workpackage', 'required' => true]));
         $inputFilter->add($factory->createInput(['name' => 'contact', 'required' => false]));
         $inputFilter->add($factory->createInput(['name' => 'public', 'required' => true]));
         $inputFilter->add($factory->createInput(['name' => 'projectCalendar', 'required' => false]));
         $fileUpload = new FileInput('file');
         $fileUpload->setRequired(true);
         $fileUpload->getValidatorChain()->attachByName('File\\Size', ['min' => '20kB', 'max' => '64MB']);
         $inputFilter->add($fileUpload);
         $this->inputFilter = $inputFilter;
     }
     return $this->inputFilter;
 }
Beispiel #26
0
 /**
  * @return \Zend\InputFilter\InputFilter|\Zend\InputFilter\InputFilterInterface
  */
 public function getInputFilter()
 {
     if (!$this->inputFilter) {
         $inputFilter = new InputFilter();
         $fileUpload = new FileInput('file');
         $fileUpload->setRequired(false);
         $fileUpload->getValidatorChain()->attachByName('File\\Extension', ['extension' => ['jpg', 'jpeg', 'png']]);
         $fileUpload->getValidatorChain()->attachByName('File\\MimeType', ['image/jpeg', 'image/jpg', 'image/png']);
         $fileUpload->getValidatorChain()->attachByName('File\\Size', ['min' => '20kB', 'max' => '4MB']);
         $fileUpload->getValidatorChain()->attachByName('File\\ImageSize', ['minWidth' => 100, 'minHeight' => 100]);
         $inputFilter->add($fileUpload);
         $this->inputFilter = $inputFilter;
     }
     return $this->inputFilter;
 }