Reputation: 2428
I have this function:
function deleteImage($image){
//$image is a varchar like 2016/10/example.jpg from MySQL
$myArray = explode('/', $image);
$result = $s3->deleteObject(array(
'Bucket' => $bucket,
'Key' => 'uploads/avatars/'.$myArray[0].'/'.$myArray[1].'/xs-'.$myArray[2]
));
}
Basically for $image = 2016/10/example.jpg
I need to delete the image located in
uploads/avatars/2016/10/xs-example.jpg
I tried to figure it out the problem for hours but it's not working and seems impossible to debug.
Upvotes: 1
Views: 36
Reputation: 1447
You're calling your function with an Array as argument, instead of deleteImage(array($verify['image']));
you should call it deleteImage($verify['image']);
Upvotes: 1
Reputation: 164760
I'd go for something like this
$key = sprintf('uploads/avatars/%s/xs-%s',
ltrim(dirname($image), '/'), basename($image));
The ltrim
is probably overkill but it's just in case your $image
variable starts with a /
.
This should handle any path depth you throw at it.
See
Upvotes: 3