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

标签 php html error-handling syntax-error

我最近正在编写一个注册脚本,并想在另一个名为“用户”的文件夹中创建一个文件夹。不知何故,创建的文件夹位于根路径(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";



            }

文件夹“0”在创建时始终为空。

最佳答案

正如@u_mulder所说,在PHP中,我们用“。”连接字符串和变量。而不是“+”符号。基于此,这应该有助于解决您的特定问题。

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";
 }

关于php - PHP错误-创建的所有文件或目录均为0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46163542/

相关文章:

javascript - 用于下载 JavaScript 和 HTML 格式的 SVG 的按钮?

excel - Excel VBA : How to stop program and return to certain step in code, 'bypassing modal limitations of MsgBox'

java - 如何使程序忽略ArrayIndexOutOfBonds错误?

php - 从开始日期计算周数

php - 在 MySQL 数据库中存储今天的日期

php - 将从 javascript 返回的值传递给 php

javascript - 本地址栏在 Mobile Chrome 上隐藏时 DIVS 调整大小

php - 为什么我的密码更改表单会自动获取值?

javascript - 编辑器中的 wordpress 双引号问题

error-handling - Yii中如何强行产生404错误