コード例 #1
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')))));
 }
コード例 #2
0
 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);
 }
コード例 #3
0
 /**
  * {@inheritDoc}
  */
 public function storeImage(UserInterface $user, array $files)
 {
     $form = $this->getServiceLocator()->get('HtProfileImage\\ProfileImageForm');
     $this->getEventManager()->trigger(__FUNCTION__, $this, ['files' => $files, 'form' => $form, 'user' => $user]);
     $inputFilter = new ProfileImageInputFilter($this->getOptions()->getUploadDirectory(), $user, $this->getOptions()->getMaxImageFileSize());
     $inputFilter->init();
     $form->setInputFilter($inputFilter);
     $form->setData($files);
     if ($form->isValid()) {
         $uploadTarget = $inputFilter->getUploadTarget();
         $filter = new RenameUpload($uploadTarget);
         $filter->setOverwrite(true);
         $filter->filter($files['image']);
         $newFileName = $this->getStorageModel()->getUserImage($user);
         $filterAlias = $this->getOptions()->getStorageFilter();
         if (!$filterAlias) {
             rename($uploadTarget, $newFileName);
             //no filter alias given, just rename
         } else {
             $filter = $this->getFilterManager()->getFilter($filterAlias);
             $image = $this->getImagine()->open($uploadTarget);
             try {
                 $image = $filter->apply($image);
                 // resize the image
             } catch (\Exception $e) {
                 return false;
             }
             $image->save($newFileName);
             // store the image
         }
         unlink($uploadTarget);
         $this->deleteCache($user);
         $this->getEventManager()->trigger(__FUNCTION__ . '.post', $this, ['image_path' => $newFileName, 'user' => $user]);
         return true;
     }
     return false;
 }
コード例 #4
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'))));
 }
コード例 #5
0
 /**
  *
  * @param array $fileInfo            
  * @param string $targetPath
  *            OPTIONAL target directory (realpath)
  * @param boolean $overwrite
  *            OPTIONAL whether or not to replace existing
  * @return array
  */
 public function createFile(array $fileInfo, $targetPath = null, $overwrite = false)
 {
     $it = $this->getStorage();
     if (empty($targetPath) || !is_dir($targetPath)) {
         $targetPath = $it->getRealPath();
     }
     $filter = new RenameUpload($targetPath);
     $filter->setOverwrite($overwrite);
     $filter->setUseUploadName(true);
     return $filter->filter($fileInfo);
 }