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. $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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.