在 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
Deleting a folder with files in Laravel
提问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);