I'm facing a weird issue : when I want to change the profil's picture of an user (using Symfony2), the function to upload the file is not call and so, my picture is not changed... But, when I create the user (the first time), the function is called and the picture is well uploaded.
Here is my code :
View :
<div class="btn btn-default image-preview-input">
<span class="glyphicon glyphicon-folder-open"></span>
<span class="image-preview-input-title">Choisir une photo de profil</span>
{{ form_widget(form.logo) }}
</div>
Entity :
/**
* @Assert\File(
* maxSize="6000000",
* mimeTypes={"image/png", "image/jpeg", "image/gif"}
* )
*
*/
public $logo;
Upload function and other for upload :
public function getAbsolutePath()
{
return null === $this->logo ? null : $this->getUploadRootDir().'/'.$this->id.'.png';
}
protected function getUploadRootDir()
{
return __DIR__.'/../../../../web/'.$this->getUploadDir();
}
protected function getUploadDir()
{
return 'uploads/events';
}
/**
* @ORM\PostPersist()
* @ORM\PostUpdate()
*/
public function upload()
{
if (null === $this->logo) {
return;
}
$path = $this->id . '.png';
if(file_exists ($this->getUploadRootDir() . $path))
unlink($this->getUploadRootDir() . $path);
$this->logo->move($this->getUploadRootDir(), $path);
$this->logo = null;
}
/**
* @ORM\PreRemove()
*/
public function storeFilenameForRemove()
{
$this->filenameForRemove = $this->getAbsolutePath();
}
/**
* @ORM\PostRemove()
*/
public function removeUpload()
{
if ($this->filenameForRemove) {
unlink($this->filenameFor Remove);
}
}
Have you got any idea of why, and how I can fix it ?
Thanks !