##1. Implementing delete I've updated ListingPhoto.php below with my code to delete files.
public function afterDelete() {
StorageManager::adapter($this->record['Photo']['adapter'])->delete($this->record['Photo']['path']);
}
I copied this directly from the docs here but when I run it I get the following error: Unable to remove the "images/.../.../...jpg" key.
I checked and the path to the file is correct. And I don't think it's a permissions problem because PHP wrote the files to that location already.
Update 1: I think the root of the problem is that my code is telling Gaufrette to do this:
public function delete($key)
{
if ($this->isDirectory($key)) {
return rmdir($this->computePath($key));
}
return unlink($this->computePath($key));
}
I'm creating multiple versions of images, and rmdir
doesn't work when the directory isn't empty.
##2. Validation now working You can see in my ListingPhoto model that I am trying to restrict which files can be uploaded...
public $actsAs = array(
'FileStorage.UploadValidator' => array(
'allowedExtensions' => array(
'jpg',
'png'
)
)
);
...but when I upload a GIF file it works fine.
Update1: After further testing, I'm pretty confident that this is a config problem, not a bug in the validation. I hacked the code to log out the settings it is using, they are definitely defaults (or something other than what I'm trying to set):
(
[localFile] => 1
[validate] =>
[allowedExtensions] => Array
(
[0] => jpg
[1] => jpeg
[2] => png
[3] => gif
)
)
Update2
I still don't know why it's happening, but I'm pretty sure that the settings are getting inherited from the parent class ImageStorage
, which has the following:
public $actsAs = array(
'Imagine.Imagine',
'FileStorage.UploadValidator' => array(
'localFile' => true,
'validate' => false,
'allowedExtensions' => array('jpg', 'jpeg', 'png', 'gif')
),
);
It would seem like I'm overriding this in my ListingPhoto class, but I don't know enough about how inheritance interacts with behaviors in CakePHP.