PHP创建文件夹
来源:百度知道 编辑:UC知道 时间:2024/05/16 16:16:29
<?php
$testdir="./1/";
$testdir="./1/2";
echo $testdir;
if(file_exists ($testdir)):
else:
mkdir ($testdir, 0777);
endif;
?>
问一下 $testdir="./1/";就可以创建 可是加一层目录就不成 谁可以帮帮我
$testdir="./1/";
$testdir="./1/2";
echo $testdir;
if(file_exists ($testdir)):
else:
mkdir ($testdir, 0777);
endif;
?>
问一下 $testdir="./1/";就可以创建 可是加一层目录就不成 谁可以帮帮我
递归。
function createFolder($path)
{
if (!file_exists($path))
{
createFolder(dirname($path));
mkdir($path, 0777);
}
}
createFolder("aa/bb/cc/dd/ee");
bool mkdir ( string$pathname [, int$mode [, bool$recursive [, resource$context ]]] )
5.0.0 The recursive parameter was added
说明:
到5.0版本后,这个函数就已经支持递归创建 ,是第三个参数, 默认是bool ,改成ture就行
例如;
<?php
// 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...');
}
?>