PHP删除文件脚本

Jop*_*per 1 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);  
}
?> 
Run Code Online (Sandbox Code Playgroud)

我正在尝试创建一个显示在每个文件旁边的删除链接/按钮,单击此按钮时,将删除相应的文件.你知道怎么做吗?

Muh*_*our 6

使用内置unlink($filepath)功能.

  • **但是不要忘记检查您的代码是否允许用户删除该文件** (3认同)