简体   繁体   English

PHP错误-创建的所有文件或目录均为0

[英]PHP Error - All Files or Directories created are 0

I was recently coding a registration script and wanted to create a folder inside another folder called "users". 我最近正在编写一个注册脚本,并想在另一个名为“用户”的文件夹中创建一个文件夹。 Somehow, the folder created was in the root path (where the php script is located) and the files, that were supposed to be written inside the folder were in a file called 0. Here's the code: 不知何故,创建的文件夹位于根路径(php脚本所在的位置)中,并且应该写在该文件夹中的文件位于名为0的文件中。以下是代码:

if (!isset($_POST["method"])){
                die("Error");
            }
            if (!isset($_POST["usernamefld"])){
                die("Error");
            }
            if (!isset($_POST["passwordfld"])){
                die("Error");
            }
            if ($_POST["method"] == "register"){
                if (!isset($_POST["emailfld"])){
                    die("Error");
                }

                if(is_dir("./users/"+$_POST["usernamefld"])){
                    die("Taken");
                }

                mkdir("/users/"+$_POST["usernamefld"]);
                echo "test";



            }

The Folder "0" is always empty when created. 文件夹“ 0”在创建时始终为空。

As @u_mulder has stated, in PHP we concat strings and variables with a "." 正如@u_mulder所说的,在PHP中,我们用“。”连接字符串和变量。 and not the "+" symbol. 而不是“ +”符号。 Based on that, this should help with your particular issue. 基于此,这应该有助于解决您的特定问题。

if (!isset($_POST["method"])){
    die("Error");
}
if (!isset($_POST["usernamefld"])){
    die("Error");
}
if (!isset($_POST["passwordfld"])){
    die("Error");
}

if ($_POST["method"] == "register"){
    if (!isset($_POST["emailfld"])){
        die("Error");
    }

    if(is_dir("./users/". $_POST["usernamefld"])){
        die("Taken");
    }

    mkdir("/users/". $_POST["usernamefld"]);
    echo "test";
 }

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

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