删除服务器文件 [英] Deleting a server file

查看:115
本文介绍了删除服务器文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种使用PHP从服务器删除文件的方法.基本上,我以这种方式在页面上列出了我的文件:

I'm looking for a way to delete a file from the server using PHP. Basically I have my files listed on a page in this manner:

<ul>
    <li><a href="delete_file.php?file=uploads/file_01.jpg">Delete File 01</a></li>
    <li><a href="delete_file.php?file=uploads/file_02.jpg">Delete File 02</a></li>
    <li><a href="delete_file.php?file=uploads/file_03.jpg">Delete File 03</a></li>
</ul>

问题是我不确定如何使我的delete_file.php文件正常工作.我相信它应该是这样的:

The problem is I'm not sure how to get my delete_file.php file to work. I believe it needs to be something like this:

<?php 
    $path="uploads/file_01.jpg";
    if(unlink($path)) echo "File Deleted"; 
?>

...但是我不确定如何获取$ path来更改我单击删除的文件.

...but I'm not sure how to get the $path to change to the file I had clicked on to delete.

推荐答案

在使用户能够删除文件的过程中,您必须格外小心,但我会给您足够的绳子来挂住自己

while you have to be incredibly careful with giving a user the ability to delete files, I'll give you enough rope to hang yourself

定义一个基本目录,该目录将包含将要删除的所有文件

define a base directory that will contain any files that will be deleted

$base_directory = '/home/myuser/';

然后删除文件

if(unlink($base_directory.$_GET['file']))
    echo "File Deleted.";

这篇关于删除服务器文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆