01 <?php
02
03 function recursive_mkdir($new_path,$permissions=0777)
04 {
05 $current_directory = getcwd();
06 $report = array('working in "'.$current_directory.'"');
07 $report[] = 'attempting to create "'.$current_directory.'/'.$new_path.'"';
08 $directories = explode('/',$new_path);
09 $new_path_str = $current_directory;
10 $n = $cn = count($directories);
11 foreach($directories as $directory)
12 {
13 if(!is_writeable($new_path_str))
14 {
15 $report[] = '"'.$new_path_str.'" is not writeable';
16 $report[] = 'aborting recursive mkdir()';
17 return $report;
18 }
19 $new_path_str .= '/'.$directory;
20 if(!file_exists($new_path_str))
21 {
22 $report[] = (mkdir($new_path_str,$permissions) ?
23 'created' : 'failed to create').' "'.$new_path_str.'"';
24 }else{
25 $report[] = 'skipped "'.$new_path_str.'"';
26 $cn--;
27 }
28 }
29 $report[] = 'created '.$cn.' of '.$n.' directories';
30 return $report;
31 }
32
33
34 // example
35 echo '<pre>';
36 print_r(recursive_mkdir('test/directory/new/folder'));
37 echo '</pre>';
38
39 ?>