2
When trying to delete an image from a specific directory I get the message that the file does not exist, but consulting the path that the code is running I see that the file does exist, and the path string is 100% correct.
I even considered permission but the code itself is who creates the folder, saves the file inside and reads, only it does not erase...
Storage::delete(public_path('uploads/'.$asset->contents->belongs_to.'/'.$asset->name));
File not found at path: var/www/xpto-digitaldev/public/uploads/2/217dade2ab7db91d12f1bca7b0cd4c82.png
Saving the file from upload;
if ($request->hasFile('image')) {
$extension = $image->getClientOriginalExtension();
$newFileName = md5(rand(0,9999)).'.'.$extension;
$image->move(public_path('uploads/'.$clientDirectory), $newFileName);
}
No need to close parentheses in
Storage::delete(public_path('uploads/'.$asset->contents->belongs_to.'/'.$asset->name);
? And if you tryunlink(public_path('uploads/'.$asset->contents->belongs_to.'/'.$asset->name));
– Miguel
@Miguel no, the function
public_path()
just wait 1 parameter, if I had forgotten to close the parentheses I would get a syntax error.– RFL
Yeah, but it doesn’t look like you closed the
delete(...
– Miguel
I already got @Miguel
– RFL
If you do with unlink ? as I told you above
– Miguel
with unlink worked @Miguel, post your response so I can approve, I will study this case also to see why the
delete
Laravel’s unlink using did not work.– RFL
Maybe add something (unwanted in this case) to the path of the file to delete. I usually do it with unlink, ok I’ll post the answer. Obgado
– Miguel