mkdir() 文件存在


mkdir() File exists

发送电子邮件和密码时,我正在尝试在图像文件夹中创建一个新目录,它会检索用户的 ID 并根据用户 ID 在图像文件夹中创建一个文件夹,但是它不起作用,因为我收到此错误:

Warning: mkdir(): File exists in C:'Users'authenticate.php on line 101

这是我尝试过的,这就是它给出的警告:

  // Otherwise, the result variable passes on the confirm-email and the confirm-password to the login function
               $result = $userVeri->login(strtolower($_POST["confirm-email"]), $_POST["confirm-password"]);
               // The row variable stores the result
               $row = $result;
               // Then make a directory in the images folder with the new user id and give the folder all priveleges
               mkdir('images/'.$row["id"],0777);
               exit;
               // Then display this message
               echo '<div class="alert alert-success">Congratulations! your account has been created. Please sign in.</div>';

有谁明白我做错了什么?

顺便说一句,即使图像文件夹中不存在文件夹,它也会发出此警告

使用 PHP 的is_dir($path_to_dir)来检查以前的目录是否存在。或者您可以使用此代码

if (!file_exists($path)) {
    mkdir($path, 0700);
}
// Otherwise, the result variable passes on the confirm-email and the confirm-password to the login function
$result = $userVeri->login(strtolower($_POST["confirm-email"]), $_POST["confirm-password"]);
// The row variable stores the result
$row = $result;
// Then make a directory in the images folder with the new user id and give the folder all priveleges
mkdir(__DIR__.'/images/'.$row["id"],0777);
// Then display this message
echo '<div class="alert alert-success">Congratulations! your account has been created. Please sign in.</div>';

我没有添加对 mkdir 成功与否的检查,也没有添加对登录方法返回的值的检查。重新检查了我的记忆想法的手册,发现首选方法现在使用魔术常量__DIR__(其中包含脚本文件的路径)