开发者

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

开发者 https://www.devze.com 2023-04-03 23:29 出处:网络
How to create folders and subfoldersusing 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

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

精彩评论

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