开发者

How to create folders and subfolders using PHP where user can give his own NAME and number of folders to be created

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 ()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜