If you have access to a linux machine, there is a command, mkdir, that takes a -p flag. Assuming you had some list of the directories and files you want to create (it could be in a database, in a data file, or programmatically generated somehow) then you could do something like this:
<?php
// you would need to define this array according to your own needs
$dirs_to_make = array(
"dir1/subdir1",
"dir2/subdir2/subsubdir2",
"dir3/subdir3/subsubdir3/subsubsubdir3"
);
$cwd = dirname(__FILE__);
foreach($dirs_to_make as $dir) {
$to_make = $cwd . DIRECTORY_SEPARATOR . $dir;
echo "making $to_make\n";
make_dir($to_make);
}
function make_dir($d) {
$mkdir_cmd = "mkdir -p " . $d;
$output = NULL; // will contain an array of output lines from the exec command
$result = NULL; // will contain the success/failure code returned by the OS. Will be zero for a valid command, non-zero otherwise
$ret = exec($mkdir_cmd, $output, $result); // $ret will contain the last line from the result from the command
if ($result) {
throw new Exception("Result was not zero, so something went wrong, result=" . $result . "\n" . print_r($output, TRUE));
}
}
?>
VERY IMPORTANT: This code would not be secure for handling user input. It'd be very important for screening the directories to make sure no one is trying to overwrite /etc/passwd or some other sensitive file.
If you are not running linux, then you'll need to write a slightly different function...something recursive probably.