/** * Called before saving the entity * * @ORM\PrePersist() * @ORM\PreUpdate() */ public function preUpload() { if (null !== $this->file) { // do whatever you want to generate a unique name $filename = sha1(uniqid(mt_rand(), true)); $this->path = $filename . '.' . $this->file->guessExtension(); } }
/** * @ORM\PrePersist() * @ORM\PreUpdate() */ public function preUpload() { if (null !== $this->file) { // faites ce que vous voulez pour générer un nom unique $filename = sha1(uniqid(mt_rand(), true)); $this->alt = $filename; $this->src = $filename . '.' . $this->file->guessExtension(); } }
/** * Lllamdo antes de guardar * * @ORM\PrePersist() * @ORM\PreUpdate() */ public function preUpload() { if (null !== $this->file) { $filename = sha1(uniqid(mt_rand(), true)); $this->path = $filename . '.' . $this->file->guessExtension(); } }
/** * @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(); }