04 May, 2010

Create nested folders using PHP


Create maximum levels of nested folders using PHP
<?php
function getWDir($id=0,$maxLvl=20){
$id1=$id;
//add 0 to the left
$id=str_pad($id,$maxLvl,0,STR_PAD_LEFT);
$dir=NULL;
for($i=0;$i<$maxLvl-2;$i=$i+2){
//get the sub-strings for generating multiple folders
$dir.=substr($id,$i,2)."/";
$dir1=substr($id,$i,2);
}
return $dir;
}
?>

1 comment:

Digital Knowledge said...

do you have any working demo for this nested dir php code?

regards