Loading Content...
© 2024 Copyrights reserved for web-brackets.com
Yasen Sayed
6 Mar 2022
Laravel
I am trying to delete a photo from my project's public folder before updating another photo. My code looks like this:
if(File::exist( $employee->avatar)){
//$employee->avatar looks /uploads/avatars/1646546082.jpg and it exist in folder
File::delete($employee->avatar);
}
This is not working in my case. If I comment on this code then another photo-updated without deleting perfectly. How can I solve the issue!
Rakshit
6 Mar 2022
If your file is existing to the mentioned directory, try below code, it will work.
Here, PHP Unlink function will work for you.
$path = public_path()."/<your path to image directory>/".$from_database->image_name;
unlink($path);
Try it, It will work for you.
Reference: PHP Unlink function - w3schools.
Eslam Zedan
6 Mar 2022
Try unlink function
$path = public_path()."/pictures/".$from_database->image_name;
unlink($path);