Posted By

IanLewis on 05/21/07


Tagged

recursive directory make


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

hudge
carlosabargues
jodm


Make directory recursively


 / Published in: PHP
 

Recursively creates a directory.

  1. //recursively creates a folder.
  2. function mk_dir($path, $rights = 0777) {//{{{
  3. //$folder_path = array(strstr($path, '.') ? dirname($path) : $path);
  4. $folder_path = array($path);
  5. } else {
  6. return;
  7. }
  8.  
  9. while([email protected]is_dir(dirname(end($folder_path)))
  10. && dirname(end($folder_path)) != '/'
  11. && dirname(end($folder_path)) != '.'
  12. && dirname(end($folder_path)) != '')
  13. {
  14. array_push($folder_path, dirname(end($folder_path)));
  15. }
  16.  
  17. while($parent_folder_path = array_pop($folder_path)) {
  18. if([email protected]mkdir($parent_folder_path, $rights)) {
  19. user_error("Can't create folder \"$parent_folder_path\".\n");
  20. }
  21. }
  22. }//}}}

Report this snippet  

You need to login to post a comment.