To create a folder tree recursively so that all new folders have the same permissions:
<?php
function mkdir_recursive($directory, $permissions=0777) {
if(!file_exists(dirname($directory))){
mkdir_recursive(dirname($directory), $permissions);
}
if(mkdir($directory, $permissions)){
chmod($directory, $permissions);
return true;
}
return false;
}
?>