如何通过用户名为用户创建多个目录 [英] How to create multiple directory for users by their user name

查看:45
本文介绍了如何通过用户名为用户创建多个目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我想让它能够通过用户名为用户创建多个目录的代码.

This is the code that i want to make it able to create multiple directory for users by their username.

现在它只创建一个名为 big

Right now it creates only one folder by the name of 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);
    }
?>

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

i want two other directory like this:

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

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

推荐答案

所有你需要做的就是修改我给你的原始脚本如下:

All you need to do is modify the original script I gave you to the following:

<?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);
    }
?>

这篇关于如何通过用户名为用户创建多个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆