I want to delete the deleted image from the cache. I made a listener but I can't remove the photo from the cache:
$this->cm->remove($entity->getFilename(), 'thumb');
I don't use vichbundle. I don't understand why I can't.
Thanks a lot
CodePudding user response:
To access to image path you can make a function inside your entity:
class Image {
public function getWebPath(): string
{
// name should have the extension (1556989965.jpeg)
return __DIR__ . '/../../public/uploads/images' . '/' . $this->getName();
}
// Or try like this:
// directory inside public folder
const UPLOAD_DIR = 'uploads/images';
//folder
public function getUploadDir(): string
{
return $this::UPLOAD_DIR;
}
public function getWebPath(): string
{
return $this->getUploadDir() . '/' . $this->getName();
}
}
and to remove cache:
$this->cm->remove($entity->getWebPath(), 'thumb');