• 递归创建多级文件目录(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是当前文件目录的层数

  • 相关阅读:
    进程实际操作篇2
    进程的实际操作篇1
    进程的理论知识
    解决套接字粘包,udp套接字对象的使用和socketserver模块实现并发
    day24-网络知识扫盲,socket的基本使用
    day23-网络编程之互联网基础,tcp/ip协议详细介绍
    day21-多态和多态性,鸭子类型,反射,内置方法,异常处理
    JAVA WEB小测
    JAVA动手动脑
    JAVA课上动手动脑问题2
  • 原文地址:https://www.cnblogs.com/runong/p/3578391.html
Copyright © 2020-2023  润新知