PHP版本是5.5.12(在WAMP 2.5下)
我想以递归方式创建directory
,目前它在我的开发计算机Windows7上,但生产系统是Linux:
define('RP_MAIN', $_SERVER['DOCUMENT_ROOT'] . 'impots/');
$dir = RP_MAIN."data/synchro/webToAndroid/";
if (mkdir($dir, 0777, true)) {
... // creating text files with data inside the webToAndroid folder
} else {
echo "cannot create";
}
首次运行脚本时会创建目录,但是当我重新运行脚本时,代码执行会转到else
块!
那么如何让mkdir
始终成功?
答案 0 :(得分:1)
这样做:
define('RP_MAIN', $_SERVER['DOCUMENT_ROOT'] . 'impots/');
$dir = RP_MAIN."data/synchro/webToAndroid/";
if(is_dir($dir)){
echo 'directory already exists';
}
else if (mkdir($dir, 0777, true)) {
... // creating text files with data inside the webToAndroid folder
} else {
echo "cannot create";
}