标签:php
嗨,我最近遇到了这个问题,但能够解决它.实际上拼写错误的路径.我想知道如何正确处理这些错误.即我的程序应继续执行,如果mkdir失败,应该安全返回false.这是我的代码
try
{
foreach($folders as $folder)
{
$path = $path.'/'.$folder;
if(!file_exists($path))
{
if(!(mkdir($path)))
{
return false;
}
}
}
return true;
}
catch (Exception $e){
return false;
}
我只是想要mkdir无法创建它.它应该返回false并且执行应该继续
编辑:这是基于社区反馈的更新代码.但我的问题仍然没有正确答案
if(!file_exists($newfolder))
{
if(mkdir($newfolder,0755,true))
{
return true;
}
}
最佳答案:
// Desired folder structure
$structure = './depth1/depth2/depth3/';
// To create the nested structure, the $recursive parameter
// to mkdir() must be specified.
if (!mkdir($structure, 0, true)) {
die('Failed to create folders...');
}
// ...
?>
标签:php
来源: https://codeday.me/bug/20190515/1109488.html