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. if (!@is_dir($path)) {
  5. $folder_path = array($path);
  6. } else {
  7. return;
  8. }
  9.  
  10. while(!@is_dir(dirname(end($folder_path)))
  11. && dirname(end($folder_path)) != '/'
  12. && dirname(end($folder_path)) != '.'
  13. && dirname(end($folder_path)) != '')
  14. {
  15. array_push($folder_path, dirname(end($folder_path)));
  16. }
  17.  
  18. while($parent_folder_path = array_pop($folder_path)) {
  19. if(!@mkdir($parent_folder_path, $rights)) {
  20. user_error("Can't create folder \"$parent_folder_path\".\n");
  21. }
  22. }
  23. }//}}}

Report this snippet  

You need to login to post a comment.