I am learning Symfony 2 and I am having problems with the UploadedFile class. I want to handle file uploads in my project, so I found out thanks to the official documentation: How to handle file uploads with Doctrine
It works very well. However, it only works locally. I use MAMP to test my project.
I tried to put my project on a Debian 6 server. The Symfony application works, but the download file does not work. When I move a file using the move () method ... I have this error:
Unable to create the "/var/www/project/Symfony/src/project/Bundle/AlbumBundle/Entity/../../../../../web/images/postes_images" directory (500 Internal Server Error)
As I said, it works very well locally. If the postes_images folder does not exist, it must be created by itself. It works well in the local ...
This is my download function:
public function upload($indexPoste, $indexPic)
{
if (null === $this->file) {
return;
}
$this->name = "poste_".$indexPoste."_pic_".$indexPic;
$this->path = "poste_".$indexPoste."_pic_".$indexPic.".".$this->file->getClientOriginalExtension();
$this->file->move($this->getUploadRootDir(), $this->path);
$this->file = null;
}
Functions for getting paths:
public function getUploadRootDir()
{
return __DIR__.'/../../../../../web/'.$this->getUploadDir();
}
protected function getUploadDir()
{
return 'images/postes_images';
}
The paths are correct because they work well in local mode. I am wondering if this is not a php configuration problem ... I did a few searches and I read that in the move method they call the "mkdir" method to create a folder if it does not exist ... If the mkdir call returns false, it returns The error I put above.
If you have an idea how to solve this problem, please. I could not find anything.
thanks