每次新用户注册时创建新的php文件


Create new php file everytime new user registers

我如何使它创建新的php文件自动每次新用户注册。我已经试过这个代码

$way="user/$userName";
if(!file_exists("$way")){
        mkdir("$way", 0755);
}

但是它只创建新文件夹而不是文件

请查看。它会告诉你你正在使用的函数的所有信息。

此外,您可以使用此网页查找将为您创建新文件的函数(例如。file_put_contents, fwrite).

<?php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "text text text written to created file'n";
fwrite($myfile, $txt);
$txt = "Jane Doe'n";
fwrite($myfile, $txt);
fclose($myfile);
?> 

对于您的情况,您应该这样写:

$way="user/$userName";
if(!file_exists($way)){
    file_put_contents($way, "");
    chmod($way, 0755)
}

现在您已经在该目录下创建了文件,并对其进行了chmod编辑。
我强烈建议您不要这样做(为用户创建php文件)。但是如果你要这么做的话,一定要把特殊字符' / * | : ? " < >$userName中去掉以确保文件名不会出现问题

使用fopen($file_location, "w")函数,php.net

$way="user/$userName";
if(!file_exists("$way")){
  fopen($way,"w");
}