public function upload() { // Si jamais il n'y a pas de fichier (champ facultatif) if (null === $this->file) { return; } // Si on avait un ancien fichier, on le supprime if (null !== $this->tempFilename) { $oldFile = $this->getUploadRootDir() . '/' . $this->id . '.' . $this->tempFilename; if (file_exists($oldFile)) { unlink($oldFile); } } // On déplace le fichier envoyé dans le répertoire de notre choix $this->file->move($this->getUploadRootDir(), $this->id . '.' . $this->url); }