Delete files by extension in laravel 5.5

0

I'm trying to delete all the files in a folder that have the extension .jpg is possible using Storage :: delete ('file.jpg');

    
asked by Andersson Meza Andrade 20.11.2017 в 18:55
source

1 answer

6

According to Laravel's official documentation, yes.

In English: Deleting files

In Spanish (this part is not yet translated): Deleting files

From the original documentation:

  

Deleting Files

     

The delete method accepts a single filename or an array of files to   remove from the disk:

use Illuminate\Support\Facades\Storage;

Storage::delete('file.jpg');

Storage::delete(['file1.jpg', 'file2.jpg']);
     

If necessary, you may specify the disk that the file should be deleted   from:

use Illuminate\Support\Facades\Storage;

Storage::disk('s3')->delete('folder_path/file_name.jpg');

But to delete ALL the files with a certain suffix you have to do the following:
* Thanks to the Pikoh's comment

File::delete(File::glob('path/*.jpg'));
    
answered by 23.11.2017 / 08:59
source