日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

创建多级目录

發布時間:2025/3/17 编程问答 12 豆豆
生活随笔 收集整理的這篇文章主要介紹了 创建多级目录 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

寫出一個能創建多級目錄的PHP函數

?

  • <?php ?
  • /* ?
  • ????21、寫出一個能創建多級目錄的PHP函數。 ?
  • *系統環境:windows/linux ?
  • *編譯環境:php5/php4 ?
  • *輸入參數:存放在in.txt,多個參數時空格分隔 ?
  • ????????????????????參數1是一個路徑,用\或者/分隔 ?
  • ????????????????????例如:www\b\c\d\e?????d:\www\b\c\d\e???/var/www/html??var/../b/c ?
  • ????輸出:out.txt ?
  • */?
  • $params=getParams(1); ?
  • $dirParh=trim($params[0]); ?
  • ?
  • mkdirP($dirParh); ?
  • ?
  • function?mkdirP($dirParh) ?
  • { ?
  • ????$dirParh=str_replace("\\",?"/",?$dirParh); ?
  • ????$paths=split("/",$dirParh); ?
  • ????$nowPath=""; ?
  • ????if(substr($dirParh,?0,1)=="/") ?
  • ????{ ?
  • ????????$nowPath="/"; ?
  • ????} ?
  • ????foreach($paths?as?$path) ?
  • ????{ ?
  • ????????if($path=="") ?
  • ????????{ ?
  • ????????????continue; ?
  • ????????} ?
  • ????????$nowPath.=$path; ?
  • ????????echo?"$nowPath\n"; ?
  • ????????//目錄不存在 ?
  • ????????if(!is_dir($nowPath)) ?
  • ????????{ ?
  • ????????????echo?"mkdir?$nowPath\n"; ?
  • ????????????//建立目錄失敗 ?
  • ????????????if(!mkdir($nowPath)) ?
  • ????????????????return?false; ?
  • ????????} ?
  • ????????$nowPath=rtrim($nowPath,"/"); ?
  • ????????$nowPath.="/"; ?
  • ????} ?
  • ????return?true; ?
  • } ?
  • ?
  • /* ?
  • ????從in.txt里讀取參數 ?
  • */?
  • function?getParams($paramNum) ?
  • { ?
  • ????$in=file_get_contents("in.txt"); ?
  • ????if($in===FALSE){ ?
  • ????????error_msg("cannot?read?in.txt,please?check?in.txt?exists\n");??? ?
  • ????} ?
  • ????$in=preg_replace("/(\s+)/i",?"?",?$in); ?
  • ????//多個參數時,按照空格分隔 ?
  • ????$parms=split("?",trim($in)); ?
  • ????if($parms===FALSE) ?
  • ????{ ?
  • ????????error_msg("cannot?get?param?from?in.txt\n"); ?
  • ????} ?
  • ????if(count($parms)?<?$paramNum) ?
  • ????{ ?
  • ????????error_msg("it?needs?$paramNum?params\n"); ?
  • ????} ?
  • ????return?$parms; ?
  • } ?
  • ?
  • /* ?
  • ????把結果輸出到輸出文件里 ?
  • ????當isClean=true時清空out.txt ?
  • */?
  • function?output($msg,$isClean=false) ?
  • { ?
  • ????if($isClean) ?
  • ????{ ?
  • ????$handle?=?fopen('out.txt',?'w'); ?
  • ????fclose($handle);???? ?
  • ????} ?
  • ????error_log($msg."\n",?3,?"out.txt"); ?
  • } ?
  • /* ?
  • ????輸入錯誤信息 ?
  • ????如果$is_exit表示輸入信息后退出 ?
  • */?
  • function?error_msg($msg,$is_exit=true) ?
  • { ?
  • ????if($is_exit) ?
  • ????????die($msg."\n"); ?
  • ????else?
  • ????????echo?$msg."\n"; ?
  • } ?
  • ?>?
  • ?

    轉載于:https://blog.51cto.com/yifangyou/618841

    總結

    以上是生活随笔為你收集整理的创建多级目录的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。