php mkdir folder tree from array -


i'm trying create folder tree array, taken string.

$folders = str_split(564); 

564 can number. goal create folder structure /5/6/4

i've managed create folders in single location, using code inspired thread -

for ($i=0;$i<count($folders);$i++) {     ($j=0;$j<count($folders[$i]);$j++) {         $path .= $folders[$i][$j] . "/";         mkdir("$path");     }     unset($path); } 

but way folders in same containing path. furthermore, how can create these folders in specific location on disk? not familiar advanced php, sorry :(

thank you.

this pretty simple.

do each loop through folder array , create string appends on each loop next sub-folder:

<?php  $folders = str_split(564);  $pathtocreatefolder = ''; foreach($folders $folder) {    $pathtocreatefolder .= directory_separator . $folder;    mkdir($folder); } 

you may add base path, folders should created initial $pathtocreatefolder.

here you'll find demo: http://codepad.org/aueryttd

or michael mentioned in comments, 1 line:

mkdir(implode(directory_separator, $folders), 0777, true); 

the true flag allows mkdir create folders recursivley. , implode put directory parts 5/6/4. directory_separator php constant slash (/) on unix machines or backslash (\) on windows.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -