/** * @ORM\PrePersist */ public function preUpload() { if (null !== $this->file) { // do whatever you want to generate a unique name $this->photo = uniqid() . '.' . $this->file->guessExtension(); } }
/** * @ORM\PrePersist */ public function preUpload() { if (null !== $this->file) { // do whatever you want to generate a unique name $this->picture_name = $this->file->getClientOriginalName(); $this->picture = $this->username . '.' . $this->file->guessExtension(); } }
/** * @ORM\PrePersist */ public function preUploadFile2() { if (null !== $this->file2) { // do whatever you want to generate a unique name $this->second_fichier_nom = $this->file2->getClientOriginalName(); $this->second_fichier = uniqid() . '.' . $this->file2->guessExtension(); } }
public function upload() { // var_dump(pathinfo($this->file, PATHINFO_EXTENSION));die(); if (null === $this->file) { return false; } else { $this->path = sha1(uniqid(mt_rand(), true)) . '.' . $this->file->guessExtension(); } $this->file->move($this->getUploadRootDir(), $this->path); unset($this->file); return true; }
/** * @ORM\PrePersist() * @ORM\PreUpdate() */ public function preUpload() { if (null !== $this->file) { // faites ce que vous voulez pour générer un nom unique $this->photo = sha1(uniqid(mt_rand(), true)) . '.' . $this->file->guessExtension(); } }