note 10798 deleted from function.mkdir by aidan
| From: | aidan@php.net | Date: | Sun, 03 Oct 2004 13:41:40 +0000 |
| Subject: | note 10798 deleted from function.mkdir by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77853@lists.php.net to get a copy of this message | ||
Note Submitter: gjukema at jukeware dot com
----
I needed a clean ForceDirectories function as used in Delphi. I grabbed the source and converted to
PHP. Just pass in a $path like "/tmp/dir1/dir2", and all "/tmp/dir1/dir2" will
be created if they don't exist - permissions allowed of coarse :).
function ForceDirectories( $path) {
if ( strlen( $path) == 0) {
return 0;
}
//
if ( strlen( $path) < 3) {
return 1; // avoid 'xyz:\' problem.
}
elseif ( is_dir( $path)) {
return 1; // avoid 'xyz:\' problem.
}
elseif ( dirname( $path) == $path) {
return 1; // avoid 'xyz:\' problem.
}
return ( ForceDirectories( dirname( $path)) and mkdir( $path, 0775));
}