简体   繁体   English

如何从PHP数组创建Windows文件夹?

[英]How to create windows folders from a PHP array?

Hopefully someone can help me. 希望有人可以帮助我。 I'm open to any suggestions, because this is my first time writing more than "Hello, World" with PHP. 我愿意接受任何建议,因为这是我第一次用PHP编写“ Hello,World”以外的文章。 I am working on writing a commission web application that allows the user to login, and see a dynamic menu based on a list of PDF files in a user folder saved server side tied to their login. 我正在编写一个允许用户登录的佣金Web应用程序,并在与用户登录相关联的服务器端用户文件夹中看到基于PDF文件列表的动态菜单。 The PHP script I am writing should check the MySQL InnoDB database, run the weekly sales report, generate a PDF and then add that PDF to a directory (if the directory isn't created then it should create the folder for file insertion). 我正在编写的PHP脚本应检查MySQL InnoDB数据库,运行每周销售报告,生成PDF ,然后将该PDF添加到目录中(如果未创建目录,则应创建用于插入文件的文件夹)。 I am using mPDF for the PDF and the creation and insertion works great, but I am struggling getting the mkdir to work with my array . 我正在使用mPDF作为PDF ,创建和插入工作都很好,但是我正在努力使mkdir与我的array It runs and then just generates a folder named Array . 它运行,然后生成一个名为Array的文件夹。 Here's what I have so far: 这是我到目前为止的内容:

try {
//Create connection
$con = new PDO("mysql:host=$servername; dbname=$database", $username, $password);
$con->exec("SET CHARACTER SET utf8");

$query = "SELECT user_id FROM users;";
$result = $con->query($query);

foreach($result as $value) {
    $filename = './reports/'.$value.'';
    if(!file_exists($filename)) {
        if(!mkdir('./reports/'.$value.'')) {
            die('Failed to create folders...');
        }
    }
}

$con = null;
}
catch(PDOException $e1) {
    echo $e1->getMessage();
}

$value is an array. $value是一个数组。 Try with - 尝试-

/reports/'.$value['user_id']

Try with this 试试这个

try {
//Create connection
$con = new PDO("mysql:host=$servername; dbname=$database", $username, $password);
$con->exec("SET CHARACTER SET utf8");

$query = "SELECT user_id FROM users;";
$result = $con->query($query);
if ($result->num_rows > 0) {
while($value = $result->fetch_assoc()) {
    $filename = './reports/'.$value["user_id"].'';
    if(!file_exists($filename)) {
        if(!mkdir('./reports/'.$value["user_id"].'')) {
            die('Failed to create folders...');
        }
    }
}
}
$con = null;
}
catch(PDOException $e1) {
    echo $e1->getMessage();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM