这是我正在使用的代码
try
{
// Execute the query to create the user
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
$elliot = $_POST['username'];
$usor = $elliot.php;
$myfile = fopen("$elliot.php", "c+") or die("Unable to open file!");
$txt = "Userpage\n";
fwrite($myfile, $txt);
fclose($myfile);
rename('$usor', 'usors/$usor');
}
基本上我正在做的是创建一个用户。创建用户后,我想要编写代码的是创建用户页面。然后我希望用户页面移动到名为usors的文件夹。
我的问题是我可以创建用户页面。但是我无法移动新创建的用户页面。
答案 0 :(得分:2)
首先,变量不会用单引号解析。
rename('$usor', 'usors/$usor');
您需要使用双引号
rename("$usor", "usors/$usor");
旁注:只有在"usors/$usor"
文件夹外运行脚本时才能访问usors
。确保路径设置正确。
然后这个$usor = $elliot.php;
您需要从那里删除.php
。
$usor = $elliot;
由于您引用了$elliot = $_POST['username'];
当然,确保设置了适当的权限。
将error reporting添加到文件的顶部,这有助于查找错误。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Then the rest of your code
旁注:只应在暂存时进行显示错误,而不是生产。
看到您正在使用POST数组,请确保您使用的表单使用的是POST方法,并且其输入带有匹配的name属性。
答案 1 :(得分:0)
你可以使用rename
php函数(http://php.net/manual/en/function.rename.php),但要确保运行php脚本的用户(apache?)有足够的权限。