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');
 }
Example #2
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);
 }
Example #3
0
 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 __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 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);
 }
 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);
 }
Example #7
0
 /**
  * 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 addInputFilter()
 {
     $inputFilter = new InputFilter\InputFilter();
     $fileInput = new InputFilter\FileInput('image-file');
     $fileInput->setRequired(true);
     $fileInput->getFilterChain()->attachByName('filerenameupload', array('target' => __DIR__ . '/../../../public/tmpuploads', 'randomize' => false, 'use_upload_name' => true));
     $inputFilter->add($fileInput);
     $this->setInputFilter($inputFilter);
 }
Example #9
0
 /**
  * Adding a RenameUpload filter to our form’s file input, with details on where the valid files should be stored
  */
 public function addInputFilter()
 {
     $inputFilter = new InputFilter\InputFilter();
     // File Input
     $fileInput = new InputFilter\FileInput('image-file');
     $fileInput->setRequired(true);
     $fileInput->getFilterChain()->attachByName('filerenameupload', array('target' => $this->_dir, 'randomize' => true));
     $inputFilter->add($fileInput);
     $this->setInputFilter($inputFilter);
 }
Example #10
0
 public function createInputFilter()
 {
     $inputFilter = new InputFilter\InputFilter();
     // File Input
     $file = new InputFilter\FileInput('file');
     $file->setRequired(true);
     $file->getFilterChain()->attachByName('filerenameupload', array('target' => '/ginosi/data/tmpuploads/', 'overwrite' => true, 'use_upload_name' => true));
     $inputFilter->add($file);
     return $inputFilter;
 }
Example #11
0
 public function setupInputFilter()
 {
     $inputFilter = new InputFilter\InputFilter();
     // File Input
     $fileInput = new InputFilter\FileInput('url');
     $fileInput->setRequired(true);
     $fileInput->getFilterChain()->attachByName('filerenameupload', array('target' => getcwd() . '/public/data/docs/file', 'randomize' => true, 'use_upload_extension' => true));
     $inputFilter->add($fileInput);
     $this->setInputFilter($inputFilter);
 }
 public function createInputFilter()
 {
     $inputFilter = new InputFilter\InputFilter();
     // File Input
     $file = new InputFilter\FileInput('file');
     $file->setRequired(true);
     $file->getFilterChain()->attachByName('filerenameupload', array('target' => './data/tmpuploads/file', 'randomize' => true));
     $inputFilter->add($file);
     return $inputFilter;
 }
 public function createInputFilter($options)
 {
     $inputFilter = new InputFilter\InputFilter();
     // File Input
     $file = new InputFilter\FileInput('file');
     $file->setRequired(true);
     $file->getFilterChain()->attachByName('filerenameupload', array('target' => $options['galleryDir'], 'overwrite' => true, 'use_upload_name' => true));
     $inputFilter->add($file);
     return $inputFilter;
 }
Example #14
0
 public function createInputFilter()
 {
     $inputFilter = new InputFilter\InputFilter();
     // File Input
     $file = new InputFilter\FileInput('file');
     $file->setRequired(false);
     $file->getFilterChain()->attachByName('filerenameupload', array('target' => './public/files/', 'overwrite' => false, 'use_upload_name' => false, 'randomize' => true));
     $inputFilter->add($file);
     return $inputFilter;
 }
Example #15
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;
 }
Example #16
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;
 }
 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);
 }
Example #18
0
 public function addInputFilter()
 {
     $inputFilter = new InputFilter\InputFilter();
     $eventFolder = '/public/uploads/events/' . date('Y-m-d');
     if (!file_exists(getcwd() . $eventFolder)) {
         mkdir(getcwd() . $eventFolder, 0777, TRUE);
     }
     // File Input
     $fileInput = new InputFilter\FileInput('thumb');
     $fileInput->setRequired(false);
     $fileInput->getFilterChain()->attachByName('filerenameupload', array('target' => '.' . $eventFolder . '/event.jpg', 'randomize' => true));
     $inputFilter->add($fileInput);
     $this->setInputFilter($inputFilter);
 }
 public function getInputFilter($contractId = 0, $code = "")
 {
     if (!$this->inputFilter) {
         $filter = new InputFilter();
         $filter->add(array('name' => 'contractId', 'required' => true, 'filters' => array(array('name' => 'Int'))));
         $filter->add(array('name' => 'contactID', 'required' => false, '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')))));
         $filter->add(array('name' => 'notes', 'required' => true, 'validators' => array(array('name' => 'StringLength', 'options' => array('max' => 500, 'min' => 1, 'encoding' => 'UTF-8')))));
         $fileInput = new FileInput('contractFile');
         $fileInput->setRequired(false);
         $fileInput->getFilterChain()->attachByName('filerenameupload', array('target' => sprintf('./data/uploads/contract/%s', $code), 'use_upload_extension' => true, 'overwrite' => true));
         $filter->add($fileInput);
         $this->InputFilter = $filter;
     }
     return $this->InputFilter;
 }
 /**
  * @return ResourceResourceInterface[]
  */
 protected function createResources()
 {
     $value = parent::getValue();
     if ($this->isValid && is_array($value)) {
         $value = $this->getResource($value);
     }
     return $value;
 }
Example #21
0
File: File.php Project: t4web/base
 public function isValid($context = null)
 {
     $result = parent::isValid($context);
     if (!$result) {
         $this->value = $this->defaultValue;
     }
     return $result;
 }
 public function createInputFilter()
 {
     $inputFilter = new InputFilter\InputFilter();
     // File Input
     $file = new InputFilter\FileInput('file');
     $file->setRequired(true);
     $file->getFilterChain()->attachByName('filerenameupload', array('target' => './data/tmpuploads/', 'overwrite' => true, 'use_upload_name' => true));
     //$file->getValidatorChain()->addByName(
     //    'fileextension', array('extension' => 'txt')
     //);
     $inputFilter->add($file);
     // Text Input
     $text = new InputFilter\Input('text');
     $text->setRequired(true);
     $inputFilter->add($text);
     return $inputFilter;
 }
 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 createInputFilter()
 {
     $inputFilter = new InputFilter\InputFilter();
     // File Collection
     $fileCollection = new InputFilter\InputFilter();
     for ($i = 0; $i < $this->numFileElements; $i++) {
         $file = new InputFilter\FileInput($i);
         $file->setRequired(true);
         $file->getFilterChain()->attachByName('filerenameupload', array('target' => './data/tmpuploads/', 'overwrite' => true, 'use_upload_name' => true));
         $fileCollection->add($file);
     }
     $inputFilter->add($fileCollection, 'file-collection');
     // Text Input
     $text = new InputFilter\Input('text');
     $text->setRequired(true);
     $inputFilter->add($text);
     return $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);
 }
Example #27
0
 public function addInputFilter($user = null)
 {
     $inputFilter = new InputFilter\InputFilter();
     $factory = new InputFactory();
     $inputFilter->add($factory->createInput(array('name' => 'fileUpload', 'required' => true, 'validators' => array(array('name' => 'Zend\\Validator\\File\\Extension', 'break_chain_on_failure' => true, 'options' => $this->getAllowedExts(), 'messages' => array(\Zend\Validator\File\Extension::FALSE_EXTENSION => 'File upload phải là file png,jpeg,jpg,gif'))))));
     // File Path
     $uri = new \Home\Service\Uri();
     $targetFolder = $uri->getSavePath($user);
     if (!file_exists($targetFolder)) {
         $oldmask = umask(0);
         mkdir($targetFolder, 0777, true);
         umask($oldmask);
     }
     $fileInput = new InputFilter\FileInput('fileUpload');
     $fileInput->setRequired(true);
     $fileInput->getFilterChain()->attachByName('filerenameupload', array('target' => $targetFolder, 'use_upload_name' => true, 'overwrite' => true));
     $inputFilter->add($fileInput);
     $this->setInputFilter($inputFilter);
 }
Example #28
0
 /**
  * {@inheritdoc}
  *
  * @param \Dms\Document\Document $document
  *
  * @see \Dms\Storage\StorageInterface::write()
  */
 public function write(\Dms\Document\Document $document)
 {
     $ret = null;
     $name = $document->getId();
     $nameMod = substr($name, 4);
     $f = substr($name, 0, 2) . '/' . substr($name, 2, 2) . '/';
     $path = $this->getBasePath() . $f;
     if (!is_dir($path)) {
         mkdir($path, 0777, true);
     }
     $p = $path . $nameMod . '.dat';
     if ($document->getSupport() === Document::SUPPORT_FILE_MULTI_PART_STR) {
         $fileInput = new FileInput(key($document->getDatas()));
         $fileInput->getFilterChain()->attachByName('filerenameupload', ['target' => $p]);
         $inputFilter = new InputFilter();
         $inputFilter->add($fileInput);
         $form = new Form();
         $form->setInputFilter($inputFilter);
         $form->setData($document->getDatas());
         if ($form->isValid()) {
             $form->getData();
         }
     } else {
         $fp = fopen($p, 'w');
         fwrite($fp, $document->getDatas());
         $document->setWeight(strlen($document->getDatas()));
         fclose($fp);
     }
     $conf_storage = $this->options->getStorage();
     if (isset($conf_storage['name']) && $conf_storage['name'] === 's3') {
         print_r($_FILES);
         $this->s3Client->copyObject(['Bucket' => $conf_storage['bucket'], 'Key' => $f . $nameMod . '.dat', 'CopySource' => $conf_storage['bucket'] . '/' . $f . $nameMod . '.dat', 'ContentType' => $document->getType(), 'ContentDisposition' => sprintf('filename=%s', null === $document->getName() ? substr($file, -1 * strlen($document->getFormat())) === $document->getFormat() ? $file : $file . '.' . $document->getFormat() : $document->getName()), 'MetadataDirective' => 'REPLACE']);
     }
     $document->setSupport(Document::SUPPORT_FILE_STR);
     $this->getEventManager()->trigger(__FUNCTION__, $this, array('path' => $path, 'short_name' => $nameMod, 'all_path' => $path . $nameMod . '.dat', 'support' => $document->getSupport(), 'name' => $name));
     $serialize = serialize($document);
     $fp = fopen($path . $nameMod . '.inf', 'w');
     $ret += fwrite($fp, $serialize);
     fclose($fp);
     $this->getEventManager()->trigger(__FUNCTION__, $this, array('path' => $path, 'short_name' => $nameMod, 'all_path' => $path . $nameMod . 'inf', 'support' => $document->getSupport(), 'name' => $name));
     return $ret;
 }
Example #29
0
 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')))));
 }
Example #30
0
 /**
  * {@inheritDoc}
  */
 public function ingest(Media $media, Request $request, ErrorStore $errorStore)
 {
     $data = $request->getContent();
     $fileData = $request->getFileData();
     if (!isset($fileData['file'])) {
         $errorStore->addError('error', 'No files were uploaded');
         return;
     }
     if (!isset($data['file_index'])) {
         $errorStore->addError('error', 'No file index was specified');
         return;
     }
     $index = $data['file_index'];
     if (!isset($fileData['file'][$index])) {
         $errorStore->addError('error', 'No file uploaded for the specified index');
         return;
     }
     $fileManager = $this->getServiceLocator()->get('Omeka\\File\\Manager');
     $file = $this->getServiceLocator()->get('Omeka\\File');
     $fileInput = new FileInput('file');
     $fileInput->getFilterChain()->attach(new RenameUpload(['target' => $file->getTempPath(), 'overwrite' => true]));
     $fileData = $fileData['file'][$index];
     $fileInput->setValue($fileData);
     if (!$fileInput->isValid()) {
         foreach ($fileInput->getMessages() as $message) {
             $errorStore->addError('upload', $message);
         }
         return;
     }
     // Actually process and move the upload
     $fileInput->getValue();
     $file->setSourceName($fileData['name']);
     $hasThumbnails = $fileManager->storeThumbnails($file);
     $fileManager->storeOriginal($file);
     $media->setFilename($file->getStorageName());
     $media->setMediaType($file->getMediaType());
     $media->setHasThumbnails($hasThumbnails);
     $media->setHasOriginal(true);
     if (!array_key_exists('o:source', $data)) {
         $media->setSource($fileData['name']);
     }
 }