递归创建多级文件目录(PHP)
下面是要创建的文件目录数组格式-$forderlist:
array(
0=>array(
"cate_name"=>"分类1",
"foldername"=>"CKJS",
"sonfolder"=>array(
0=>array(
"cate_name"=>"分类1_1",
"foldername"=>"CKZT"
),
1=>array(
"cate_name"=>"分类1_2",
"foldername"=>"CKCT"
)
)
),
1=>array(
"cate_name"=>"分类2",
"foldername"=>"YYZK",
"sonfolder"=>array(
0=>array(
"cate_name"=>"分类2_1",
"foldername"=>"FWQY"
),
1=>array(
"cate_name"=>"分类2_2",
"foldername"=>"GSRY"
),
2=>array(
"cate_name"=>"分类2_3",
"foldername"=>"Others"
)
)
),
2=>array(
"cate_name"=>"分类3",
"foldername"=>"SBZK",
"sonfolder"=>array(
0=>array(
"cate_name"=>"分类3_1",
"foldername"=>"CKSB"
),
1=>array(
"cate_name"=>"分类3_2",
"foldername"=>"CLSB"
),
2=>array(
"cate_name"=>"分类3_3",
"foldername"=>"FDSB"
),
3=>array(
"cate_name"=>"分类3_4",
"foldername"=>"XFSB"
)
)
),
3=>array(
"cate_name"=>"分类_4",
"foldername"=>"QYYS"
),
4=>array(
"cate_name"=>"分类5",
"foldername"=>"RYJS",
"sonfolder"=>array(
0=>array(
"cate_name"=>"分类5_1",
"foldername"=>"GSJG"
),
1=>array(
"cate_name"=>"分类5_2",
"foldername"=>"YGZP"
)
)
),
5=>array(
"cate_name"=>"分类6",
"foldername"=>"XTBB",
"sonfolder"=>array(
0=>array(
"cate_name"=>"分类6_1",
"foldername"=>"GLYY"
),
1=>array(
"cate_name"=>"分类6_2",
"foldername"=>"XTYY"
),
2=>array(
"cate_name"=>"分类6_3",
"foldername"=>"SOP"
),
3=>array(
"cate_name"=>"分类6_4",
"foldername"=>"KPI"
)
)
)
)
下面是递归创建多级文件目录函数:
function
create_forder_list($forderlist,$cate_forder_path,$i)
{
$parent_id=mysql_insert_id();
foreach($forderlist as
$k=>$v)
{
$sqlstr="insert into
".DB_PRE."uppic_cate(cate_name,cate_parentid,foldername,level,cate_forder_path)
values(‘".$v["cate_name"]."‘,‘".$parent_id."‘,‘".$v["foldername"]."‘,‘".($i+1)."‘,‘".$cate_forder_path.‘/‘.$v["foldername"]."‘)";
$GLOBALS[‘mysql‘]->query($sqlstr);
@mkdir(CMS_PATH.$cate_forder_path.‘/‘.$v["foldername"]);
if(isset($v["sonfolder"]))
{
create_forder_list($v["sonfolder"],$cate_forder_path.‘/‘.$v["foldername"],$i+1);
}
}
}
附注:$forderlist是上面的文件目录数组,$cate_forder_path是当前文件目录的父目录路径,$i是当前文件目录的层数
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。