PHP: Recursive Create Path (if not exists)
Thursday, July 31st, 2008Handling directories and files with PHP is a snap. However, with this handy function you can always be sure that the destination directory path for your files will exist.
If you pass a path with a filename at teh end, set the second parameter to true eg make_path($path, true)
-
/*Create Directory Tree if Not Exists
-
If you are passing a path with a filename on the end, pass true as the second parameter to snip it off */
-
function make_path($pathname, $is_filename=false){
-
-
if($is_filename){
-
-
-
}
-
-
// Check if directory already exists
-
-
-
return true;
-
-
}
-
-
// Ensure a file does not already exist with the same name
-
-
-
-
-
return false;
-
-
}
-
-
// Crawl up the directory tree
-
-
-
if (make_path($next_pathname, $mode)) {
-
-
-
-
}
-
-
}
-
-
return false;
-
-
}



