Für alle, die noch nicht PHP 5 verwenden, hier mkdir rekursiv.
PHP-Code:
<?php
function mkdirRecursive($directory, $mode = 0777)
{
if (is_dir($directory)) {
// nothing to do
return true;
}
$directories = explode(DIRECTORY_SEPARATOR, $directory);
for ($i = $x = count($directories); $i >= 0; --$i) {
// step backward until a parent path exists ..
$current = implode(DIRECTORY_SEPARATOR, array_slice($directories, 0, $i));
if (is_dir($current)) {
for ($k = $i; $k < $x; ++$k) {
// .. then step forward again ..
$current = implode(DIRECTORY_SEPARATOR, array_slice($directories, 0, $k + 1));
// .. and try to create the directory one by one
if (!@mkdir($current, $mode)) {
return false;
}
}
break;
}
}
// base path does not exist
return false;
}
Der Pfad wird am DIRECTORY_SEPARATOR zerlegt, das heißt "C:/test1/test2" funktioniert nicht, da / von Windows zwar toleriert wird, der eigentliche DIRECTORY_SEPARATOR ist aber \
'C:\test1\test2' funktioniert. Es ist ebenfalls zu beachten, dass \ innerhalb von doppelten Anführungszeichen eine Sonderrolle einnimmt.
Wer gemerkt hat, dass die Funktion garnicht rekursiv ist kriegt 100 Punkte
