PHP没有写入文件

时间:2012-09-22 02:26:51

标签: php io

我正在制作注册表单,但似乎无法写入文本文件。在这段代码中,我将一个人的真实姓名放在他们的文件中,在acc / pplid / [name] .txt文件根本不写 - 回声不输出任何东西。我正在计算机上运行Microsoft Webmatrix。提前谢谢!

        $irlname = $_POST["irlname"];
        $name = $_POST["username"];
        $email = $_POST["email"];
        $password = $_POST["password"];
        $name = htmlentities($name);

        echo $name;
        file_put_contents("acc/pplid/".name.".txt", $irlname);
        echo file_get_contents("acc/pplid/".$name.".txt");

1 个答案:

答案 0 :(得分:2)

file_put_contents("acc/pplid/".name.".txt", $irlname);

应该是

file_put_contents("acc/pplid/".$name.".txt", $irlname);

除非将name定义在其他地方,否则我会说检查写权限。在file_put_contents之前使用file_existsis_dir检查文件夹的状态。

示例

if(is_dir("acc/pplid") && is_writable("acc/pplid")){
    file_put_contents("acc/pplid/".$name.".txt", $irlname);
} else echo "A problem with the folder occurred";