Reputation: 761
I want to upload a file with symfony, but I always get an error when submitting my form.
This is my entity code:
public function rootPath($directory) {
return $this->getUploadRootDir($directory) . '/' . User::cleanFilename($this->file->getClientOriginalName());
}
public function getWebPath($directory) {
return $this->getUploadDir($directory) . '/' . User::cleanFilename($this->file->getClientOriginalName());
}
public function getUploadDir($directory) {
return $this->user->getDir() . '/' . $this->user->getDirectoryName() . '/' . $directory;
}
protected function getUploadRootDir($directory) {
return $this->user->getRootDir() . '/' . $this->user->getDirectoryName() . '/' . $directory;
}
public function upload($directory) {
// la propriété « file » peut être vide si le champ n'est pas requis
if (null === $this->file) {
return;
}
$this->filename = User::cleanFilename($this->file->getClientOriginalName());
$this->file->move($this->getUploadRootDir($directory), $this->filename);
// $this->url = $this->file->getClientOriginalName();
//$this->filename=$this->getWebPath($directory);
$result = $this->rootPath($directory);
$this->file = null;
return $result;
}
And this is what symfony return:
Message Origin Cause
Le fichier n'a pas été trouvé. file Symfony\Component\Validator\ConstraintViolation
Object(Symfony\Component\Form\Form).data.file = file3.csv
I tried several times but I always get the same problem.
What is the cause of this error?
Upvotes: 0
Views: 1735
Reputation: 761
Problem resolved,
I added enctype="multipart/form-data"
and then the problem has been resolved
Upvotes: 2