How to delete file from public folder in laravel 5.1

后端 未结 17 1721
悲哀的现实
悲哀的现实 2020-11-30 09:02

I want to delete a News from database and when I hit the delete button all data from database deleted but the image is remains in upload folder. So, how do I this to work. t

17条回答
  •  囚心锁ツ
    2020-11-30 09:33

    You could use PHP's unlink() method just as @Khan suggested.

    But if you want to do it the Laravel way, use the File::delete() method instead.

    // Delete a single file

    File::delete($filename);
    

    // Delete multiple files

    File::delete($file1, $file2, $file3);
    

    // Delete an array of files

    $files = array($file1, $file2);
    File::delete($files);
    

    And don't forget to add at the top:

    use Illuminate\Support\Facades\File; 
    

提交回复
热议问题