Make directory recursively


/ Published in: PHP
Save to your folder(s)

Recursively creates a directory.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.