无法使用变量 (PHP) 创建新目录


Not able to create new directory with variable (PHP)

您好,我正在尝试在用户/文件夹中创建一个目录。当用户注册时,正在打开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($userPath, 0777);