laravel 创建新目录返回 mkdir():文件存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39992815/
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
Creating a new directory returns mkdir(): File exists
提问by ThomH
When I try to make a new directory to store images in I'm getting
当我尝试创建一个新目录来存储图像时,我得到了
Error: mkdir(): File exists.
错误:mkdir():文件存在。
I'm not sure what this could be... My code
我不确定这可能是什么......我的代码
Storage::makeDirectory(public_path('img/uploads/projects' . $project->id), 0777);
My goal is to create a new folder for every project and put their images in it.
我的目标是为每个项目创建一个新文件夹并将其图像放入其中。
回答by Chandana Kumara
Check first file exists. If not create folder.
检查第一个文件是否存在。如果没有创建文件夹。
$path='img/uploads/projects' . $project->id;
if (!file_exists($path)) {
mkdir($path, 0777, true);
}