Example #1
0
 public static function uploadFileToStorage(File $file)
 {
     $filename = 'file_' . substr(md5(uniqid(rand())), 6) . '_' . $file->getClientOriginalName();
     $path = self::uploadPath();
     $file->move($path, $filename);
     return $path . DIRECTORY_SEPARATOR . $filename;
 }
Example #2
0
 /**
  * @ORM\PrePersist()
  * @ORM\PreUpdate()
  */
 public function preUpload()
 {
     if (null === $this->file) {
         return;
     }
     //On add un extension pour le fichier.
     $this->url = $this->file->guessExtension();
     //Le alt est le nom du fichier du client.
     $this->alt = $this->file->getClientOriginalName();
 }
Example #3
0
 /**
  * Called after entity persistence
  *
  * @ORM\PostPersist()
  * @ORM\PostUpdate()
  */
 public function upload()
 {
     // The file property can be empty if the field is not required
     if (null === $this->file) {
         return;
     }
     // Use the original file name here but you should
     // sanitize it at least to avoid any security issues
     // move takes the target directory and then the
     // target filename to move to
     $this->file->move($this->getUploadRootDir(), $this->path);
     // Set the path property to the filename where you've saved the file
     $this->path = $this->file->getClientOriginalName();
     //Create future attibut alt of <img>
     $this->alt->{$this}->path;
     // Clean up the file property as you won't need it anymore
     $this->file = null;
 }