我希望能够在公共html中的html文件中点击按钮,删除公共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>
答案 0 :(得分:2)
好的,所以文件夹路径应该是“/ home / user / public_html /”而不是“home / user / public_html /".