1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
public function getFullPicturePath() {
return null === $this->picture ? null : $this->getUploadRootDir(). $this->picture;
}
protected function getUploadRootDir() {
// the absolute directory path where uploaded documents should be saved
return $this->getTmpUploadRootDir().$this->getId()."/";
}
protected function getTmpUploadRootDir() {
// the absolute directory path where uploaded documents should be saved
return __DIR__ . '/../../../../web/uploads/movies/';
}
/**
* @ORM\PrePersist()
* @ORM\PreUpdate()
*/
public function uploadPicture() {
// the file property can be empty if the field is not required
if (null === $this->picture) {
return;
}
if(!$this->id){
$this->picture->move($this->getTmpUploadRootDir(), $this->picture->getClientOriginalName());
}else{
$this->picture->move($this->getUploadRootDir(), $this->picture->getClientOriginalName());
}
$this->setPicture($this->picture->getClientOriginalName());
}
/**
* @ORM\PostPersist()
*/
public function movePicture()
{
if (null === $this->picture) {
return;
}
if(!is_dir($this->getUploadRootDir())){
mkdir($this->getUploadRootDir());
}
copy($this->getTmpUploadRootDir().$this->picture, $this->getFullPicturePath());
unlink($this->getTmpUploadRootDir().$this->picture);
}
/**
* @ORM\PreRemove()
*/
public function removePicture()
{
unlink($this->getFullPicturePath());
rmdir($this->getUploadRootDir());
} |
Partager