我有一个基本的PHP脚本,显示目录的文件内容。下面是该脚本:PHP删除文件脚本
<?php
$Dept = "deptTemplate";
if(isset($_REQUEST['dir'])) {
$current_dir = $_REQUEST['dir'];
} else {
$current_dir = 'docs';
}
if ($handle = opendir($current_dir)) {
while (false !== ($file_or_dir = readdir($handle))) {
if(in_array($file_or_dir, array('.', '..'))) continue;
$path = $current_dir.'/'.$file_or_dir;
if(is_file($path)) {
echo '`<a href="/Implementation/'.$Dept.'/'.$path.'">'.$file_or_dir.'</a> - [Delete button/link]<br/>`';
} else {
echo '`<a href="testFolderiFrame.php?dir='.$path.'">`'.$file_or_dir."\n`</a>` - [Delete button/link]`<br/>`";
}
}
closedir($handle);
}
?>
我想创建一个删除链接/按钮旁边显示每个文件并点击时,相应的文件将被删除。你会知道如何做到这一点?
**但是不要忘记检查你的代码,允许用户删除该文件** – ThiefMaster 2011-01-30 17:45:17
你能告诉我在代码中添加这个函数的位置吗? (我对php的使用经验不多) – Jopper 2011-01-30 18:09:12