Laravel 从公共删除目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36420312/
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
Laravel delete directory from public
提问by Jamie
How could I delete a directory from the public folder? Right now I try this:
如何从公共文件夹中删除目录?现在我试试这个:
Storage::deleteDirectory($directory);
But that looks in the storage folder?
但这看起来在存储文件夹中?
回答by tommy
You can use Illuminate\Filesystem\Filesystem
for this. Laravel provides the File
facade for easy access:
您可以Illuminate\Filesystem\Filesystem
为此使用。Laravel 提供了File
方便访问的门面:
File::deleteDirectory(public_path('path/to/folder'));
The method will return true
if it succeeds, false
if it fails.
true
如果成功,该方法将返回,false
如果失败。
回答by Muihlinn
To be accessible by Storage you should define the filesystem name in config/filesystems
and be sure to have the right permissions to be able to what you want to do.
要由 Storage 访问,您应该在其中定义文件系统名称,config/filesystems
并确保拥有正确的权限才能执行您想要执行的操作。
Then something like Storage::deleteDirectory($directory);
assuming that $directory
is something you got properly from the corresponding resource.
然后Storage::deleteDirectory($directory);
假设这$directory
是您从相应资源中正确获得的东西。
Read the docs here
在这里阅读文档
回答by Mehdi Shi
You can use this:
你可以使用这个:
$path = 'upload/pic/foldername/';
if (\File::exists($path)) \File::deleteDirectory($path);
foldername is deleting with all files in it.
foldername 正在删除其中的所有文件。
回答by Alief
You can use File instead of Storage. Try this one:
您可以使用文件而不是存储。试试这个:
File::deleteDirectory(public_path($directory));