/**
  * Execute the job.
  */
 public function handle()
 {
     /**
      * Create Extra
      * @var Extra $extra
      */
     $extra = $this->product->extras()->create($this->data);
     $aspectDir = @$this->data['aspect_ratio'] ?: '16x9';
     /**
      * Move Extra Content to folder
      */
     $path = '/image/products-extras/';
     $extraID = $extra->getAttribute('id');
     $productCode = $this->product->getAttribute('code');
     $filename = $productCode . '-extra-image-' . $extraID . '.' . $this->image->guessExtension();
     $image = $this->image->move(base_path() . $path, $filename);
     $extra->setAttribute('image', $path . $filename);
     $filename = $productCode . '-extra-video-' . $extraID . '.' . $this->video->guessExtension();
     $video = $this->video->move(base_path() . $path . $aspectDir . '/', $filename);
     $extra->setAttribute('video', $filename);
     $extra->save();
     /**
      * Announce ExtraWasCreated
      */
     event(new ExtraWasCreated($extra));
 }
Esempio n. 2
0
 /**
  * @ORM\PrePersist()
  * @ORM\PreUpdate()
  */
 public function preUpload()
 {
     if (null === $this->file) {
         return;
     }
     $this->url = $this->file->guessExtension();
     $this->alt = $this->file->getClientOriginalName();
 }
Esempio n. 3
0
 /**
  * @ORM\PrePersist()
  * @ORM\PreUpdate()
  */
 public function preUpload()
 {
     // Si jamais il n'y a pas de fichier (champ facultatif)
     if (null === $this->file) {
         return;
     }
     // Le nom du fichier est son id, on doit juste stocker �galement son extension
     // Pour faire propre, on devrait renommer cet attribut en � extension �, plut�t que � extension �
     $this->extension = $this->file->guessExtension();
     // Et on g�n�re l'attribut alt de la balise <img>, � la valeur du nom du fichier sur le PC de l'internaute
     $this->alt = $this->file->getClientOriginalName();
 }
Esempio n. 4
0
 /**
  * @ORM\PrePersist()
  * @ORM\PreUpdate()
  */
 public function preUpload()
 {
     //        if (null !== $this->getFile()) {
     //            // do whatever you want to generate a unique name
     //            $filename   = sha1(uniqid(mt_rand(), true));
     //            $this->path = $filename.'.'.$this->getFile()->guessExtension();
     //        }
     if (null !== $this->file) {
         // faites ce que vous voulez pour générer un nom unique
         $this->path = sha1(uniqid(mt_rand(), true)) . '.' . $this->file->guessExtension();
     }
 }
 /**
  * Determines whether a passed photo file
  * is valid.
  * @throws  InalidMediaTypeException If the file extension isn't jpeg, jpg, png, bmp or gif
  *
  * @param  Symfony\Component\HttpFoundation\File\UploadedFile   $file
  * @return boolean
  */
 public function validateFile(File $file)
 {
     // if ( ! $file->isValid())
     // {
     //     throw new PhotoUploadException('error occured while uploading photo' , $file->getError());
     // }
     $input = ['extension' => $file->guessExtension()];
     $rules = ['extension' => 'in:jpeg,jpg,png,bmp,gif'];
     $validation = $this->validator->make($input, $rules);
     if ($validation->fails()) {
         throw new InvalidMediaTypeException($file->guessExtension());
     }
     return true;
 }
Esempio n. 6
0
 /**
  * Make 3 copy from original user avatar with compression: small, medium and big
  * @param iUser $user
  */
 public function copyFile(iUser $user)
 {
     // move file to original folder
     $upload = $this->file->move(root . '/upload/user/avatar/original/', $user->id . '.' . $this->file->guessExtension());
     try {
         // big image
         $this->resizeAndSave($upload, $user->id, 'big');
         $this->resizeAndSave($upload, $user->id, 'medium');
         $this->resizeAndSave($upload, $user->id, 'small');
     } catch (\Exception $e) {
         if (App::$Debug) {
             App::$Debug->addException($e);
         }
     }
 }
Esempio n. 7
0
 public function getFileMd5Name(UploadedFile $file)
 {
     $ext = $file->guessExtension();
     $md5 = md5_file($file->getRealPath());
     $name = $md5 . '.' . $ext;
     return $name;
 }
 /**
  * @param UploadedFile $file
  * @param Photo        $photo
  */
 public function uploadPhoto(UploadedFile $file, Photo &$photo)
 {
     $fileName = time() . '.' . $file->guessExtension();
     $file->move($this->getUploadDir(), $fileName);
     $photo->setName($fileName);
     $photo->setOriginalName($file->getClientOriginalName());
 }
Esempio n. 9
0
 public static function upload(UploadedFile $file, $bucketName)
 {
     if (!$file->isValid()) {
         throw new \Exception(trans('validation.invalid_file'));
     }
     $bucket = Bucket::find($bucketName);
     if (!empty($bucket->mimeTypes()) && !in_array($file->getMimeType(), $bucket->mimeTypes())) {
         throw new \Exception(trans('validation.invalid_file_type'));
     }
     if (!empty($bucket->maxSize()) && !in_array($file->getClientSize(), $bucket->maxSize())) {
         throw new \Exception(trans('validation.invalid_file_size'));
     }
     $disk = Storage::disk($bucket->disk());
     $media = Media::create(['mime' => $file->getMimeType(), 'bucket' => $bucketName, 'ext' => $file->guessExtension()]);
     $disk->put($bucket->path() . '/original/' . $media->fileName, File::get($file));
     if (is_array($bucket->resize())) {
         foreach ($bucket->resize() as $name => $size) {
             $temp = tempnam(storage_path('tmp'), 'tmp');
             Image::make(File::get($file))->fit($size[0], $size[1])->save($temp);
             $disk->put($bucket->path() . '/' . $name . '/' . $media->fileName, File::get($temp));
             unlink($temp);
         }
     }
     return $media;
 }
 /**
  * @ORM\PrePersist()
  * @ORM\PreUpdate()
  */
 public function preUpload()
 {
     if (null !== $this->file) {
         $name = preg_replace('/([^a-z0-9\\-\\_])/i', '', $this->getName());
         $this->setPath($this->getUploadDir() . '/' . $name . time() . '.' . $this->file->guessExtension());
     }
 }
Esempio n. 11
0
 /**
  * @param UploadedFile $uploadedFile
  */
 function upload(UploadedFile $uploadedFile)
 {
     $path = sha1(uniqid(mt_rand(), true)) . '.' . $uploadedFile->guessExtension();
     $this->setPath($path);
     $this->setName($uploadedFile->getClientOriginalName());
     $uploadedFile->move($this->getUploadRootDir(), $path);
 }
Esempio n. 12
0
 public function moveUploadedFile(UploadedFile $file, $uploadBasePath, $relativePath)
 {
     $originalName = $file->getFilename() . '.' . $file->guessExtension();
     $targetFileName = $relativePath . DIRECTORY_SEPARATOR . $originalName;
     $targetFilePath = $uploadBasePath . DIRECTORY_SEPARATOR . $targetFileName;
     $ext = $file->getExtension();
     $i = 1;
     while (file_exists($targetFilePath) && md5_file($file->getPath()) != md5_file($targetFilePath)) {
         if ($ext) {
             $prev = $i == 1 ? "" : $i;
             $targetFilePath = $targetFilePath . str_replace($prev . $ext, $i++ . $ext, $targetFilePath);
         } else {
             $targetFilePath = $targetFilePath . $i++;
         }
     }
     $targetDir = 'uploads';
     if (!is_dir($targetDir)) {
         $ret = mkdir($targetDir, 777, true);
         if (!$ret) {
             throw new \RuntimeException("Could not create target directory to move temporary file into.");
         }
     }
     $file->move($targetDir, basename($targetFilePath));
     return str_replace($uploadBasePath . DIRECTORY_SEPARATOR, "", $targetFilePath);
 }
Esempio n. 13
0
 public function preUpload()
 {
     if (null !== $this->file_domicile) {
         // do whatever you want to generate a unique name
         $this->path_domicile = uniqid() . '.' . $this->file_domicile->guessExtension();
     }
     if (null !== $this->file_prestations) {
         // do whatever you want to generate a unique name
         $this->path_prestations = uniqid() . '.' . $this->file_prestations->guessExtension();
     }
     if (null !== $this->file_salaire_1) {
         // do whatever you want to generate a unique name
         $this->path_salaire_1 = uniqid() . '.' . $this->file_salaire_1->guessExtension();
     }
     if (null !== $this->file_salaire_2) {
         // do whatever you want to generate a unique name
         $this->path_salaire_2 = uniqid() . '.' . $this->file_salaire_2->guessExtension();
     }
     if (null !== $this->file_salaire_3) {
         // do whatever you want to generate a unique name
         $this->path_salaire_3 = uniqid() . '.' . $this->file_salaire_3->guessExtension();
     }
     if (null !== $this->file_impots) {
         // do whatever you want to generate a unique name
         $this->path_impots = uniqid() . '.' . $this->file_impots->guessExtension();
     }
 }
Esempio n. 14
0
 /**
  * @ORM\PrePersist()
  * @ORM\PreUpdate()
  */
 public function preUpload()
 {
     if ($this->file === null) {
         return;
     }
     $this->extension = $this->file->guessExtension();
     $this->alt = $this->file->getClientOriginalName();
 }
Esempio n. 15
0
 public function preUpload()
 {
     if (null !== $this->file) {
         $filename = sha1(uniqid(mt_rand(), true));
         $this->path = $this->getUploadDir() . '/' . $filename . '.' . $this->file->guessExtension();
         return $this->path;
     }
 }
Esempio n. 16
0
 public function upload(UploadedFile $file, $fileName = null)
 {
     if (null === $fileName) {
         $fileName = md5(uniqid()) . '.' . $file->guessExtension();
     }
     $file->move($this->targetDir, $fileName);
     return $fileName;
 }
Esempio n. 17
0
 protected function processImage(UploadedFile $uploaded_file)
 {
     $path = UPLOADS_PATH . '/avatars/';
     //getClientOriginalName() => Returns the original file name.
     $file_name = sha1(uniqid(mt_rand(), true)) . '.' . $uploaded_file->guessExtension();
     $uploaded_file->move($path, $file_name);
     return $file_name;
 }
 /**
  * @ORM\PrePersist()
  * @ORM\PreUpdate()
  */
 public function preUpload()
 {
     
     if (null !== $this->file) {            
         $this->setPath($this->getUploadDir().'/'.$this->name. time().'.'. $this->file->guessExtension());
         
     }
 }
Esempio n. 19
0
 /**
  * @param Rank $rank
  * @param UploadedFile $image
  */
 public function updateImage(Rank $rank, UploadedFile $image)
 {
     $this->deleteImage($rank);
     $extension = $image->guessExtension();
     if ($image->move($this->imageDirectory, $rank->getId() . '.' . $extension)) {
         $rank->setImageExtension($extension);
         $this->updateRank($rank);
     }
 }
 public function createAttachmentFromUpload(UploadedFile $file)
 {
     $attachment = new Attachment();
     $attachment->setUuid(Uuid::uuid4());
     $attachment->setFileName($attachment->getUuid() . '.' . $file->guessExtension());
     $attachment->setMimeType($file->getMimeType());
     $file->move(self::UPLOAD_PATH, $attachment->getFileName());
     return $attachment;
 }
 /**
  * Check if extension is valid
  * @param UploadedFile $file
  * @return bool
  */
 protected function checkExtension(UploadedFile $file)
 {
     $extension = $file->guessExtension();
     $extensions = array('jpg', 'jpeg', 'png');
     if (in_array($extension, $extensions)) {
         return true;
     }
     return false;
 }
Esempio n. 22
0
 /**
  * @param Member $member
  * @param UploadedFile $photo
  */
 public function updatePhoto(Member $member, UploadedFile $photo)
 {
     $this->deletePhoto($member);
     $extension = $photo->guessExtension();
     if ($photo->move($this->photoDirectory, $member->getId() . '.' . $extension)) {
         $member->setPhotoExtension($extension);
         $this->update($member);
     }
 }
 public function createFromFile(UploadedFile $newMedia, SiteModel $site, UserAccountModel $user, $title = null, $sourceText = null, $sourceURL = null)
 {
     global $CONFIG;
     if ($newMedia && in_array(strtolower($newMedia->guessExtension()), MediaModel::getAllowedImageExtensions())) {
         $media = new MediaModel();
         $media->setSiteId($site->getId());
         $media->setStorageSize($newMedia->getSize());
         $media->setTitle($title);
         $media->setSourceText($sourceText);
         $media->setSourceUrl($sourceURL);
         $media->setMd5(md5_file($newMedia->getRealPath()));
         $this->create($media, $user);
         $storeDirectory = $CONFIG->fileStoreLocation . DIRECTORY_SEPARATOR . "media";
         $extension = strtolower($newMedia->guessExtension());
         $newMedia->move($storeDirectory, $media->getId() . "." . $extension);
         return $media;
     }
 }
Esempio n. 24
0
 /**
  * @ORM\PrePersist()
  * @ORM\PreUpdate()
  */
 public function preUpload()
 {
     if (null === $this->file) {
         return;
     }
     $this->extention = $this->file->guessExtension();
     $this->name = str_replace('.' . $this->extention, '', $this->file->getClientOriginalName());
     $this->slugify();
     $this->mimeType = $this->file->getMimeType();
 }
Esempio n. 25
0
 /**
  * Moves a file in its right place with a generated name
  *
  * @param Symfony\Component\HttpFoundation\File\UploadedFile $file File to move
  *
  * @return string New file name
  */
 protected function moveFile(UploadedFile $file)
 {
     $path = $this->getUploadPath();
     $name = $this->generateFilename($path, $file->guessExtension());
     while (file_exists($path . $name)) {
         $name = $this->generateFilename($extension);
     }
     $file->move($path, $name);
     return $name;
 }
Esempio n. 26
0
 /**
  * @ORM\PrePersist
  * @ORM\PreUpdate
  */
 public function preUpload()
 {
     if (null !== $this->pdf_copy_file) {
         $oldFile = $this->getAbsolutePdfCopy();
         if (file_exists($oldFile)) {
             unlink($oldFile);
         }
         // do whatever you want to generate a unique name
         $this->pdf_copy = sha1(uniqid(mt_rand(), true)) . '.' . $this->pdf_copy_file->guessExtension();
     }
 }
 /**
  * Guess the extension of the given file.
  *
  * @param UploadedFile $file
  *
  * @return string|null
  */
 private function getExtension(UploadedFile $file)
 {
     $originalName = $file->getClientOriginalName();
     if ($extension = pathinfo($originalName, PATHINFO_EXTENSION)) {
         return $extension;
     }
     if ($extension = $file->guessExtension()) {
         return $extension;
     }
     return null;
 }
Esempio n. 28
0
 /**
  * @param $description
  * @param UploadedFile $file
  * @param Paket $paket
  * @return Dokumen
  */
 public static function create($description, UploadedFile $file, Paket $paket)
 {
     $fileName = uniqid() . '.' . $file->guessExtension();
     $dokumen = new Dokumen();
     $dokumen->setCreatedAt(new \DateTime());
     $dokumen->setDescription($description);
     $dokumen->setFile($file);
     $dokumen->setFilename($fileName);
     $dokumen->setPaket($paket);
     return $dokumen;
 }
Esempio n. 29
0
 /**
  * @param UploadedFile $file
  * @return Document
  */
 public function add(UploadedFile $file)
 {
     $document = new Document();
     $document->setExtension($file->guessExtension())->setMime($file->getMimeType())->setName($file->getClientOriginalName())->setSize($file->getSize());
     if (is_null($document->getExtension())) {
         $document->setExtension($file->getClientOriginalExtension());
     }
     $this->em->persist($document);
     $this->em->flush();
     $file->move($this->directory . '/' . substr($document->getId(), 0, 1), $document->getId() . '.' . $document->getExtension());
     return $document;
 }
Esempio n. 30
0
 /**
  * Set file.
  *
  * @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
  */
 public function setFile($file)
 {
     $this->file = $file;
     if (isset($this->path)) {
         $this->temp = $this->path;
         $this->path = null;
     } else {
         $this->path = 'initial';
     }
     $this->extension = $file->guessExtension();
     $this->originalName = $file->getClientOriginalName();
 }