生活随笔
收集整理的這篇文章主要介紹了
创建多级目录
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
寫出一個能創建多級目錄的PHP函數
?
<?php ??????????$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; ?} ?????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; ?} ??????function?output($msg,$isClean=false) ?{ ?????if($isClean) ?????{ ?????$handle?=?fopen('out.txt',?'w'); ?????fclose($handle);???? ?????} ?????error_log($msg."\n",?3,?"out.txt"); ?} ?????function?error_msg($msg,$is_exit=true) ?{ ?????if($is_exit) ?????????die($msg."\n"); ?????else?????????echo?$msg."\n"; ?} ??>? ?
轉載于:https://blog.51cto.com/yifangyou/618841
總結
以上是生活随笔為你收集整理的创建多级目录的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。