How to create folders and subfolders using PHP where user can give his own NAME for the folders and s开发者_Go百科ubfolders and number of folders that has to be created
<?php
$pathToDirCreationTopDir = '/var/www/path/to';
$mainDir = $_GET['mainDir'];
$subDirs = $_GET['subDirs'];
if (!mkdir($pathToDirCreationTopDir . '/' . $mainDir)) {
echo 'Main dir creation failed!';
exit;
}
$pathToDirCreationTopDir = $pathToDirCreationTopDir . '/' . $mainDir;
foreach ($subDirs as $subDirName) {
if (!mkdir($pathToDirCreationTopDir . '/' . $subDirName)) {
echo 'Sub dir creation failed!';
exit;
}
}
If you work on Windows you need to replace the slashes (/) with backslashes ()
精彩评论