Delete file Laravel

2

When trying to delete an image from a specific directory I get the message that the file does not exist, however, referring to the path that the code is running I see that the file exists yes, and the path string is 100% correct. / p>

I came to consider permission but the code itself is who creates the folder, saves the file inside and reads, only it does not delete ...

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 the upload;

if ($request->hasFile('image')) {
   $extension = $image->getClientOriginalExtension();
   $newFileName = md5(rand(0,9999)).'.'.$extension;
   $image->move(public_path('uploads/'.$clientDirectory), $newFileName);
}
    
asked by anonymous 17.08.2016 / 22:28

2 answers

2

With Storage::delete(...) , I've never tried, I always use the php native function unlink , try the following:

unlink(public_path('uploads/'.$asset->contents->belongs_to.'/'.$asset->name));
    
17.08.2016 / 22:54
1

You can use File .

File::delete('img/imagem.png');

Do not forget the:

use File;

File can be the same as Storage .

    
19.08.2016 / 16:02