在 Laravel 中删除包含文件的文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41207731/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 14:57:01  来源:igfitidea点击:

Deleting a folder with files in Laravel

phplaraveldirectory

提问by Mark

What is the proper syntax when deleting a folder with files in laravel 5.2?

在 laravel 5.2 中删除包含文件的文件夹时的正确语法是什么?

Here is my syntax when deleting the folder from the DB and DIR

这是从 DB 和 DIR 中删除文件夹时的语法

$folder = Folder::find($id);
$folder_path = storage_path('locker').'/'. $folder->folder_title;
$folder->delete();
 `rmdir($folder_path);`
\Session::flash('success', 'Folder Deleted!');
return back();

回答by Adiyya Tadikamalla

After much frustration I got the solution.

经过多次挫折,我得到了解决方案。

Use 'File' instead of 'Storage'

使用“文件”而不是“存储

File::deleteDirectory($path);

回答by Alexey Mezenin

The deleteDirectory may be used to remove a directory and all of its files

deleteDirectory 可用于删除目录及其所有文件

Storage::deleteDirectory($directory);

https://laravel.com/docs/5.3/filesystem#directories

https://laravel.com/docs/5.3/filesystem#directories