note 10798 added to mkdir
| From: | gjukema at jukeware dot com | Date: | Mon, 22 Jan 2001 23:40:53 +0000 |
| Subject: | note 10798 added to mkdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-10090@lists.php.net to get a copy of this message | ||
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));
}
http://www.php.net/manual/en/function.mkdir.php