PHP 在单击按钮时从 public_html 中的文件中删除 public_html 中的所有文件夹和文件

标签 php html

我希望能够通过单击公共(public) html 中的 html 文件中的按钮来删除公共(public) html 中的所有文件夹和文件。下面的代码是我尝试过的,但没有成功。

该文件的位置是“home/user/public_html/delete.html”。但似乎不起作用

<?php
    function remove_directory($directory) {
        if (!is_dir($directory)) return;

        $contents = scandir($directory);
        unset($contents[0], $contents[1]);

        foreach($contents as $object) {
            $current_object = $directory.'/'.$object;
            if (filetype($current_object) === 'dir') {
                remove_directory($current_object);
            } else {
                unlink($current_object);    
            }
        }

        rmdir($directory);
    }

    if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['dir'])) {
        $dir = $_POST['dir'];
        if ($dir[0] != '.') remove_directory("$dir");
    }
    ?>
    <h1>DELETE</h1>
    <form action="" method="post">
        <input type="hidden" name="dir" value="home/user/public_html/" />
        <input type="submit" name="delete"/>
    </form>

最佳答案

好的,所以文件夹路径应该是“/home/user/public_html/”而不是“home/user/public_html/”。

关于PHP 在单击按钮时从 public_html 中的文件中删除 public_html 中的所有文件夹和文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34955599/

相关文章:

php - mysql where子句限制?

javascript - 自举 |具有哈希分隔符样式的 URL

html - 如何在 React-bootstrap 中有一个固定在顶部但不在小视口(viewport)上的导航栏?

html - 制作部分不在屏幕上的 div,它不会向屏幕添加水平滚动

php - Laravel 验证 HTML 选择输入的数字数组

php - 尝试包含导航栏页面时文件解析错误

html - 位置 :fixed image overlapping divs

html - 如何去除图片的边框?

php - Laravel 5.2 中的正则表达式验证

php - 使用 PHP7 时,是否需要用 PHPDoc 记录方法?