douhao6271 2013-09-25 02:33
浏览 42
已采纳

通过链接删除服务器中的文件

I am listing the text files that I have on my server, and I want to add a link to download that file and/or delete it.

It works perfectly, but the problem is that when I press the delete button it deletes the file and opens a new page, and what I want is that when I press the delete button, deletes the file and refresh the page.

This is my code:

$user = $_SESSION['email'];
$direc = "./WSN/" . $user;
$directorio = opendir($direc); //current route
$vacio = true;

while ($archivo = readdir($directorio)) //get a file and then another on
{
    if (($archivo!=".")&&($archivo!=".."))//check whether or not a directory
    {
        echo "
            <b>
                <a href=\"".$direc."/".$archivo."\" target=\"_blank\">".$archivo."</a>
            </b>
            -
            <b>
                <a href=\"include/download.php?file=.".$direc."/".$archivo."\" title='download'>Download</a>
            </b>
            -
            <b>
                <a href=\"include/delete.php?file=.".$direc."/".$archivo."\" title='delete'>Delete</a>
            </b>

            <br />
        ";

        $vacio = false;
    }
}

And this is the code of delete.php:

$file = $_GET['file'];

unlink($file);

Someone can help me?

[Edit]: "abreuna" means "opens one".

  • 写回答

1条回答 默认 最新

  • douyanguo7964 2013-09-25 02:45
    关注

    Why don't you simply add to your delete.php, after the unlink($file):

    header('Location: list.php');
    

    Assuming that your first code snippet is on a file named list.php

    BTW, be aware that you delete.php opens a big security hole. Anyone can ask your script to delete any file that your php process can access.

    The same goes to download, anyone can download files you don't want to be downloaded.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)