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
 public static function rename($file, $location, $prefix, $name = null)
 {
     $extension = pathinfo($file["name"], PATHINFO_EXTENSION);
     $newName = $name ? $name : uniqid($prefix . '-') . rand(1000000, 9999999) . "." . $extension;
     $loc = ROOT_PATH . '/public/' . $location . '/' . $newName;
     try {
         $rename = new RenameUpload(array('target' => $loc, 'overwrite' => true));
         $filter = $rename->filter($file);
         $mode = 644;
         if (!$filter || !chmod($loc, octdec($mode))) {
             return false;
         }
         return $newName;
     } catch (\Exception $e) {
         return false;
     }
 }
 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);
 }
 /**
  * Override moveUploadedFile
  *
  * If the request is not HTTP, or not a PUT or PATCH request, delegates to
  * the parent functionality.
  *
  * Otherwise, does a `rename()` operation, and returns the status of the
  * operation.
  *
  * @param string $sourceFile
  * @param string $targetFile
  * @return bool
  * @throws FilterRuntimeException in the event of a warning
  */
 protected function moveUploadedFile($sourceFile, $targetFile)
 {
     if (null === $this->request || !method_exists($this->request, 'isPut') || !$this->request->isPut() && !$this->request->isPatch()) {
         return parent::moveUploadedFile($sourceFile, $targetFile);
     }
     ErrorHandler::start();
     $result = rename($sourceFile, $targetFile);
     $warningException = ErrorHandler::stop();
     if (false === $result || null !== $warningException) {
         throw new FilterRuntimeException(sprintf('File "%s" could not be renamed. An error occurred while processing the file.', $sourceFile), 0, $warningException);
     }
     return $result;
 }
 /**
  * This method is overloaded so that the final target points to a URI using S3 protocol
  *
  * {@inheritdoc}
  */
 protected function getFinalTarget($uploadData)
 {
     // We cannot upload without a bucket
     if (null === $this->options['bucket']) {
         throw new MissingBucketException('No bucket was set when trying to upload a file to S3');
     }
     // Get the tmp file name and convert it to an S3 key
     $key = trim(str_replace('\\', '/', parent::getFinalTarget($uploadData)), '/');
     if (strpos($key, './') === 0) {
         $key = substr($key, 2);
     }
     return "s3://{$this->options['bucket']}/{$key}";
 }
 /**
  * {@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;
 }
Beispiel #7
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'))));
 }
 /**
  * {@inheritdoc}
  */
 public function filter($value)
 {
     $return = parent::filter($value);
     $imagePath = isset($return['tmp_name']) ? $return['tmp_name'] : $return;
     $watermarkOptions = $this->getWatermark();
     $watermark = new Watermark();
     if (!$watermarkOptions['image'] instanceof Watermark\Adapter\AdapterInterface) {
         $watermarkOptions['image'] = new $watermarkOptions['adapter']($watermarkOptions['image']);
     }
     $watermark->setWatermark($watermarkOptions['image']);
     $watermark->setPosition($watermarkOptions['position']);
     $watermark->setMargins($watermarkOptions['margins']);
     if (!$imagePath instanceof Watermark\Adapter\AdapterInterface) {
         $imagePath = new $watermarkOptions['adapter']($imagePath);
     }
     $watermark->filter($imagePath);
     return $return;
 }
Beispiel #9
0
 /**
  * {@inheritDoc}
  */
 protected function getFinalTarget($uploadData)
 {
     if (is_array($uploadData)) {
         $this->uploadData = $uploadData;
     }
     $target = parent::getFinalTarget($uploadData);
     $info = pathinfo($target);
     if ($this->getRandomize()) {
         $subPath = FileUtils::getStoreSubPath($info['filename'], $this->getStoreLevels());
     }
     if (!$subPath) {
         return $target;
     }
     $info['dirname'] .= DIRECTORY_SEPARATOR . $subPath;
     if (!is_dir($info['dirname'])) {
         mkdir($info['dirname'], 0755, true);
     }
     $path = realpath($info['dirname']) . DIRECTORY_SEPARATOR . $info['basename'];
     return $path;
 }
 /**
  * @return void
  */
 public function testConstructTruncatedTarget()
 {
     $filter = new FileRenameUpload('*');
     $this->assertEquals('*', $filter->getTarget());
     $this->assertEquals($this->_oldFile, $filter($this->_oldFile));
     $this->assertEquals('falsefile', $filter('falsefile'));
 }
Beispiel #11
0
 public function getFinalTarget($uploadData)
 {
     return parent::getFinalTarget($uploadData);
 }
 /**
  *
  * @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);
 }
Beispiel #13
0
 /**
  * @inheritdoc
  */
 protected function getFinalTarget($uploadData)
 {
     return trim(str_replace('\\', '/', parent::getFinalTarget($uploadData)), '/');
 }
 /**
  * {@inheritdoc}
  */
 public function __construct(array $options = array())
 {
     // Change default options (e.g. test.png will become test_4b3403665fea6.png
     $options = array_merge(array('use_upload_name' => true, 'randomize' => true), $options);
     parent::__construct($options);
 }
Beispiel #15
0
 /**
  * @param array $fileData
  * @return static
  * @throws \InvalidArgumentException
  */
 public static function upload(array $fileData)
 {
     if (!is_array($fileData)) {
         throw new \InvalidArgumentException('Invalid fileData for upload');
     }
     if (!isset($fileData['name']) && count($fileData) == 1) {
         return self::upload(array_pop($fileData));
     }
     $renameUpload = new RenameUpload(self::getDefaultUploadBasePath() . DIRECTORY_SEPARATOR . $fileData['name']);
     $renameUpload->filter($fileData);
     return new static($fileData['name']);
 }
Beispiel #16
0
 /**
  * Save resource
  * 
  * @access public
  * @param Courses\Entity\Resource $resource
  * @param array $data ,default is empty array
  * @param bool $isAdminUser ,default is bool false
  * @param string $userEmail ,default is null
  */
 public function save($resource, $data = array(), $isAdminUser = false, $userEmail = null)
 {
     $notifyAdminFlag = false;
     $editFlag = false;
     if (empty($data)) {
         $editFlag = true;
     }
     if ($isAdminUser === false) {
         $resource->setStatus(Status::STATUS_NOT_APPROVED);
         $notifyAdminFlag = true;
     }
     $this->query->setEntity('Courses\\Entity\\Resource')->save($resource, $data);
     if (isset($data["fileAdded"])) {
         // save added resources
         foreach ($data["fileAdded"] as $fileKey => $fileValue) {
             $filter = new RenameUpload($fileValue["uploadOptions"]);
             $resource = clone $resource;
             $uploadedFile = $filter->filter($fileValue);
             $resource->setFile($uploadedFile);
             $resource->setName($data["nameAdded"][$fileKey]);
             $this->query->setEntity('Courses\\Entity\\Resource')->save($resource);
         }
     }
     if ($notifyAdminFlag === true) {
         $this->sendMail($userEmail, $editFlag);
     }
 }
Beispiel #17
0
 /**
  * Saves uploaded file to server dump folder with filename
  *  LISBACKUP_upload_DDMMYYYY_HHMMSS.sql
  * TODO: Sanity checking, that the input file is actually an SQL dump.
  * 
  * @param array $file
  */
 public function upload($file)
 {
     try {
         $this->setFileName('upload');
         $filter = new \Zend\Filter\File\RenameUpload(_PATH_ . $this->fileName);
         $filter->filter($file);
         if ($filter->filter($file)['error'] == 4) {
             return array('error' => true, 'exception' => "You must select a file for upload.");
         } else {
             var_dump($filter->filter($file));
             return array('error' => false);
         }
     } catch (Exception $ex) {
         return array('error' => true, 'exception' => 'This Error happened:<br>' . $ex);
     }
 }
 public function attach(AttachmentFieldsetProvider $form, $type = 'file', $appendId = null)
 {
     if (!$form->isValid()) {
         throw new Exception\RuntimeException(print_r($form->getMessages(), true));
     }
     if (!$appendId) {
         $this->assertGranted('attachment.create');
         $attachment = $this->createAttachment();
         $type = $this->getTypeManager()->findTypeByName($type);
         $attachment->setType($type);
     } else {
         $attachment = $this->getAttachment($appendId);
         $this->assertGranted('attachment.append', $attachment);
     }
     $data = $form->getData()['attachment'];
     if (!isset($data['file']) || $data['file']['error']) {
         throw new Exception\NoFileSent();
     }
     $file = $data['file'];
     $filename = $file['name'];
     $size = $file['size'];
     $filetype = $file['type'];
     $pathinfo = pathinfo($filename);
     $extension = isset($pathinfo['extension']) ? '.' . $pathinfo['extension'] : '';
     $hash = uniqid() . '_' . hash('ripemd160', $filename) . $extension;
     $location = $this->findParentPath($this->moduleOptions->getPath()) . '/' . $hash;
     $webLocation = $this->moduleOptions->getWebpath() . '/' . $hash;
     $filter = new RenameUpload($location);
     $filter->filter($file);
     return $this->attachFile($attachment, $filename, $webLocation, $size, $filetype);
 }