public function onValidate(ValidationEvent $event)
 {
     $extension = $event->getFile()->getExtension();
     if ($extension != "ogg" && $extension != "mp3" && $extension != "wav") {
         throw new ValidationException('Le fichier doit etre un fichier audio');
     }
 }
 /**
  * Validate a submited file
  *
  * @param ValidationEvent $event
  * @throws \Oneup\UploaderBundle\Uploader\Exception\ValidationException
  */
 public function onValidate(ValidationEvent $event)
 {
     try {
         $this->validator->validate($event->getType(), $event->getFile(), 'upload_validators');
     } catch (JbFileUploaderValidationException $e) {
         throw new ValidationException($e->getMessage(), null, $e);
     }
 }
 public function onValidate(ValidationEvent $event)
 {
     $config = $event->getConfig();
     $file = $event->getFile();
     if ($file->getSize() > $config['max_size']) {
         throw new ValidationException('error.maxsize');
     }
 }
 public function onValidate(ValidationEvent $event)
 {
     $config = $event->getConfig();
     $file = $event->getFile();
     if (count($config['disallowed_mimetypes']) == 0) {
         return;
     }
     $mimetype = $file->getExtension();
     if (in_array($mimetype, $config['disallowed_mimetypes'])) {
         throw new ValidationException('error.blacklist');
     }
 }
 public function onValidate(ValidationEvent $event)
 {
     $config = $event->getConfig();
     $file = $event->getFile();
     if (count($config['allowed_mimetypes']) == 0) {
         return;
     }
     $mimetype = $file->getMimeType();
     if (!in_array($mimetype, $config['allowed_mimetypes'])) {
         throw new ValidationException('error.whitelist');
     }
 }
Пример #6
0
 /**
  * Validates file before upload
  *
  * @param ValidationEvent $event
  */
 public function onUploadValidation(ValidationEvent $event)
 {
     $file = $event->getFile();
     $extensions = $this->factory->getParameter('allowed_extensions');
     $maxSize = $this->factory->getModel('asset')->getMaxUploadSize('B');
     if ($file !== null) {
         if ($file->getSize() > $maxSize) {
             $message = $this->translator->trans('mautic.asset.asset.error.file.size', array('%fileSize%' => round($file->getSize() / 1048576, 2), '%maxSize%' => round($maxSize / 1048576, 2)), 'validators');
             throw new ValidationException($message);
         }
         if (!in_array(strtolower($file->getExtension()), array_map('strtolower', $extensions))) {
             $message = $this->translator->trans('mautic.asset.asset.error.file.extension', array('%fileExtension%' => $file->getExtension(), '%extensions%' => implode(', ', $extensions)), 'validators');
             throw new ValidationException($message);
         }
     }
 }
 public function onValidate(ValidationEvent $event)
 {
     $config = $event->getConfig();
     $file = $event->getFile();
     if (empty($config['allowed_mimetypes'])) {
         return;
     }
     $mimetype = $file->getMimeType();
     $extension = strtolower($file->getExtension());
     if (!isset($config['allowed_mimetypes'][$mimetype])) {
         throw new ValidationException('error.whitelist');
     }
     if (empty($config['allowed_mimetypes'][$mimetype]) || in_array($extension, $config['allowed_mimetypes'][$mimetype])) {
         return;
     }
     throw new ValidationException('error.whitelist');
 }