Reputation: 604
My folders on cloudinary... product/banner product/profile_pic
I have banners and profile_pictures of items...Now On cloudinary i want to delete particular banner of product....
For uploading my code is like Which works totally FINE:
public function cloudinary($myfile,$folder)
{
$cloudUpload = \Cloudinary\Uploader::upload($myfile["banner"]["tmp_name"] , array("folder" => $folder));
$cloud_path = $cloudUpload['url'];
return $cloud_path;
}
Now How to delete the image when i am editing product detail?So,I want to perform operation like unlink file from folder ON "CLOUDINARY WITH PHP"
Upvotes: 1
Views: 3499
Reputation: 9
I also have issue with Cloudinary delete but its now resolved am able to get the public id like this:
// Extract the public ID from the URL $publicId = pathinfo($imageUrl, PATHINFO_FILENAME);
whie wanting to delete it i tried this as per Cloudinary documentation: Cloudinary::destroy($publicId);
But it didn't work out why? Its because i have the image inside "Property Images" folder created in my Cloudinary account so i have to resought to this way before it works:
use CloudinaryLabs\CloudinaryLaravel\Facades\Cloudinary; //my Import at top of the file
Cloudinary::destroy('Property Images/'.$publicId);
If you know you are saving into a Folder, try and always append the folder name like that before the $public id
Upvotes: 0
Reputation: 1560
You can delete Image using destroy method:
\Cloudinary\Uploader::destroy($id);
where $id
is the id of image. In your case you can get the id from $cloudUpload['public_id']
Upvotes: 3