note 56850 added to function.mkdir
| From: | funke at osu1 dot php dot net | Date: | Fri, 16 Sep 2005 19:51:34 +0000 |
| Subject: | note 56850 added to function.mkdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-95304@lists.php.net to get a copy of this message | ||
Ive onlybeen coding in PHP for a couple of months so i Don't have all the syntax tricks down
yet.
I wrote this function to create all the dirs in a path if they don't exist. its not actually
recursive but i was to lazy to change the name :)
theoretically i want it to work for both win and nix. As soon my project manager gets me a win box
i'm gonna test it out. anyrevisions to the function below would be appreciated.
<?php
// \
function recur_mkdirs($path, $mode = 0777) //creates directory tree recursively
{
//$GLOBALS["dirseparator"]
$dirs = explode($GLOBALS["dirseparator"],$path);
$pos = strrpos($path, ".");
if ($pos === false) { // note: three equal signs
// not found, means path ends in a dir not file
$subamount=0;
}
else {
$subamount=1;
}
for ($c=0;$c < count($dirs) - $subamount; $c++) {
$thispath="";
for ($cc=0; $cc <= $c; $cc++) {
$thispath.=$dirs[$cc].$GLOBALS["dirseparator"];
}
if (!file_exists($thispath)) {
//print "$thispath<br>";
mkdir($thispath,$mode);
}
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.mkdir.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56850
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56850&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56850&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56850&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56850&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56850&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+56850&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56850&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56850&report=yes
Search -- http://master.php.net/manage/user-notes.php