这是我要使其能够通过用户名为用户创建多个目录的代码。

现在,它仅创建一个名为big的文件夹

<?php
    $db = new PDO("..."); // Connection details here
    $stmt = $db->prepare("SELECT * from some_table where user_id = :id"); // Finds the information based on an ID. Change this depending on how you want the select to work
    $stmt->execute(array(':id' => "1")); // Gives value to :id and executes the statement
    $row = $stmt->fetch();

    // Then run your code

    if (!file_exists(ROOT_PATH.'user/upload/'.$row['UserName'].'/avatar/big')) {
        mkdir(ROOT_PATH.'user/upload/'.$row['UserName'].'/avatar/big', 0777, true);
    }
?>


我想要这样的另外两个目录:

user/upload/'.$row['UserName'].'/avatar/small

user/upload/'.$row['UserName'].'/avatar/original

最佳答案

您需要做的就是修改我给您的以下原始脚本:

<?php
    $db = new PDO("..."); // Connection details here
    $stmt = $db->prepare("SELECT * from some_table where user_id = :id"); // Finds the information based on an ID. Change this depending on how you want the select to work
    $stmt->execute(array(':id' => "1")); // Gives value to :id and executes the statement
    $row = $stmt->fetch();

    // Then run your code

    if (!file_exists(ROOT_PATH.'user/upload/'.$row['UserName'].'/avatar/big')) {
        mkdir(ROOT_PATH.'user/upload/'.$row['UserName'].'/avatar/big', 0777, true);
    }

    if (!file_exists(ROOT_PATH.'user/upload/'.$row['UserName'].'/avatar/small')) {
        mkdir(ROOT_PATH.'user/upload/'.$row['UserName'].'/avatar/small', 0777, true);
    }

    if (!file_exists(ROOT_PATH.'user/upload/'.$row['UserName'].'/avatar/original')) {
        mkdir(ROOT_PATH.'user/upload/'.$row['UserName'].'/avatar/original', 0777, true);
    }
?>

关于php - 如何通过用户名为用户创建多个目录,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25971188/

10-16 15:17
查看更多