【发布时间】:2013-06-30 14:28:57
【问题描述】:
您好,我正在尝试在 users/ 文件夹中创建一个目录。当用户注册时,正在打开一个 vpb_save_details.php。并运行 mkdir 以创建用户名作为目录名称的用户。
用户注册正常,但是没有创建目录的问题,甚至没有创建/user目录。
如果我运行这段代码:
<?php
mkdir("blah", 0777);
?>
目录 bla 已创建,但如果我运行我的代码 vpb_save_details.php,则没有任何反应。
这是部分代码:
//If the user is validated and every thing is alright, then save the user details and display success message to the user
//otherwise, display error message to the user
if ($vpb_error == '')
{
//Encrypt user information with Base64 before saving them to a file
if(fwrite($vpb_database, "\r\n".base64_encode($fullname)."::::::::::".base64_encode($username)."::::::::::".base64_encode($email)."::::::::::".base64_encode($encrypted_user_password).""))
{
echo '<font style="font-size:0px;">completed</font>';
echo '<div class="info">Congrats <b>'.$fullname.'</b>, you have registered successful. <br>You may now click on the login button to log into your account.<br>Thanks.</div>';
//
// HERE! I create a folder in the users directory with the variable $username as username
//
$newUserName = $username;
$userPath = "users/".$newUserName;
mkdir("$userPath", 0777);
//copy("index.php",$userPath/index.php);
}
else
{
echo '<div class="info">Sorry, your account creation was unsuccessful, please try again (1).</div>';
}
}
else
{
echo $vpb_error;
}
fclose($vpb_database);
我完全不知道问题可能是什么?代码:
$newUserName = $username;
$userPath = "users/".$newUserName;
mkdir("$userPath", 0777);
应该可以正常工作,还是我遗漏了一个小细节?
【问题讨论】:
-
用户文件夹是否存在?如果不将您的
mkdir更改为mkdir("$userPath", 0777, true);。如果确实存在,请检查用户目录的权限以确保它是可写的 -
你确定 if 语句返回 true 吗?
-
@chislonden 成功了,我以为用户目录将由 mkdir 创建...