Exemplo n.º 1
5
 /**
  * @param AssetInterface $asset
  * @param UploadedFile   $file
  *
  * @return AssetVersion
  */
 public function createVersionFromFile(AssetInterface $asset, UploadedFile $file)
 {
     list($width, $height) = getimagesize($file->getRealPath());
     $extension = File::extension($file->getClientOriginalName(), $file->getMimetype());
     $version = $this->version->create(['asset_id' => $asset->getId(), 'extension' => $extension, 'filesize' => $file->getClientSize(), 'filename' => $file->getClientOriginalName(), 'width' => $width, 'height' => $height, 'edited_at' => time(), 'edited_by' => Auth::getPerson()->getId(), 'mimetype' => $file->getMimeType(), 'metadata' => File::exif($file->getRealPath())]);
     $file->move($asset->directory(), $version->id);
     return $version;
 }
Exemplo n.º 2
0
 /**
  * PrePersist()
  */
 public function preUpload()
 {
     if (null === $this->getFile()) {
         return;
     }
     try {
         $this->setMimeType($this->file->getMimetype());
     } catch (FileNotFoundException $e) {
         $this->setMimeType($this->file->getClientMimeType());
     }
     // set the path property to the filename where you'ved saved the file
     $filename = $this->sanitise($this->file->getClientOriginalName());
     $this->setFilename($filename);
 }