Laravel 5.4: how to delete a file stored in storage/app

后端 未结 8 1577
臣服心动
臣服心动 2020-12-30 00:22

I want to delete a file that is stored in storage/app/myfolder/file.jpg. I have tried the following codes but none of this works:

use File    
$file_path = u         


        
8条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-30 00:57

    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(['file.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');
    

    Delete A Directory

    Finally, the deleteDirectory method may be used to remove a directory and all of its files:

    Storage::deleteDirectory($directory);
    

提交回复
热议问题