I am using liipimaginebundle and everything works fine except for deleting and updating cached images when updating the original image. I would like to know how I can do this
config.yml
liip_imagine: resolvers: default: web_path: ~ filter_sets: cache: ~ travel_75_55: quality: 80 filters: thumbnail: { size: [75, 55], mode: outbound } travel_270_161: quality: 75 filters: thumbnail: { size: [270, 161], mode: outbound}
And this is Object: Image
/** * Image * * @ORM\HasLifecycleCallbacks */ class Image { //................. public $file; public function setFile($file) { $this->file = $file; if (null !== $this->url) { $this->tempFilename = $this->url; $this->url = null; $this->alt = null; } } public function getFile() { return $this->file; } private $tempFilename; /** * @ORM\PrePersist() * @ORM\PreUpdate() */ public function preUpload() { if (null === $this->file) { return; } $this->url = $this->file->guessExtension(); $this->alt = $this->file->getClientOriginalName(); } /** * @ORM\PostPersist() * @ORM\PostUpdate() */ public function upload() { if (null === $this->file) { return; } if (null !== $this->tempFilename) { $oldFile = $this->getUploadRootDir().'/'.$this->id.'.'.$this->tempFilename; if (file_exists($oldFile)) { unlink($oldFile); } } $this->file->move( $this->getUploadRootDir(), $this->id.'.'.$this->url ); } /** * @ORM\PreRemove() */ public function preRemoveUpload() { $this->tempFilename = $this->getUploadRootDir().'/'.$this->id.'.'.$this->url; } /** * @ORM\PostRemove() */ public function removeUpload() { if (file_exists($this->tempFilename)) { unlink($this->tempFilename); } } public function getUploadDir() { return 'uploads/img/travels'; } protected function getUploadRootDir() { return __DIR__.'/../../../../web/'.$this->getUploadDir(); } public function getWebPath() { return $this->getUploadDir().'/'.$this->getId().'.'.$this->getUrl(); } }
php symfony liipimaginebundle
hous
source share