小编thi*_*ard的帖子

尝试取消链接目录时出现“是一个目录”错误

我正在尝试创建一个函数,该函数将定期运行以删除任何没有活动用户的旧“用户”文件夹。这是我的功能:

function delete_temp_user_files() {
    $dir = $_SERVER['DOCUMENT_ROOT'] . "/users/";
    $dir_files = array();
    $dir_files = scandir($dir);
    foreach ($dir_files as $username) {
        if ($username == "." || $username == "..") continue;
        if (!user_exist($username)) {
            $dir1 = $_SERVER['DOCUMENT_ROOT'] . "/users/" . $username;
            if (!is_dir($dir1)) continue;
            if (file_exists($dir1)) unlink($dir1);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是当它尝试删除目录时,我收到错误消息“警告:取消链接(/path/to/users/delete1/):在线 /page.php 中的目录...”我知道该目录存在,因为我可以在目录中看到它,无论如何它使用 scandir() 找到了它。

我使用 unlink 删除其他脚本中的这些相同文件夹,它工作正常。目录不是空的,所以我不能使用 rmdir()。

我不熟悉权限或类似的东西,这是某种问题吗?如果我只使用 PHP 脚本删除文件和文件夹(例如当用户单击运行我编写的脚本的删除按钮时),我是否需要担心权限?

更新:

网上搜了下终于找到删除目录的方法了

function delete_dir($directory) {
    foreach(glob("{$directory}/*") as $file)
    {
        if(is_dir($file)) { 
            delete_dir($file);
        } else {
            unlink($file);
        }
    }
    rmdir($directory);
}
Run Code Online (Sandbox Code Playgroud)

php

3
推荐指数
1
解决办法
1万
查看次数

onclick触发器无法首次单击

我很困惑为什么onclick函数在第一次点击时没有注册.每次使用onclick触发器的div都必须在第一次点击两次.

function selected(elmnt) {
  if (elmnt.style.backgroundColor == "transparent")
    elmnt.style.backgroundColor = "#990000"
  else
    elmnt.style.backgroundColor = "transparent"
}
Run Code Online (Sandbox Code Playgroud)
#container {
  background-color: transparent;
  height: 100px;
  width: 100px;
}
Run Code Online (Sandbox Code Playgroud)
<div id="container" onclick="selected(this)">click me</div>
Run Code Online (Sandbox Code Playgroud)

我在这里错过了什么吗?

javascript onclick

2
推荐指数
1
解决办法
3229
查看次数

标签 统计

javascript ×1

onclick ×1

php ×1