doupishan3309 2016-08-13 11:52
浏览 199

PHP使用按钮下载,删除和重命名文件

So I am creating a small file manager with php that will list in a table all available files in a directory on my server and provide me with a downloads or delete option.

This is my code:

<html>
<head>
    <title>My first PHP Page</title>
</head>

<body>
    <iframe id="my_iframe" style="display:none;"></iframe>
    <table border="1">
    <?php
        $dir = 'uploads';
        $files = scandir($dir);
        sort($files);
        $count = -1 ;
        foreach ($files as $file) {
            if ($file != '.' && $file != '..') {
                $str_URL = "uploads".$file;
                echo "<tr>";
                echo "<td>";
                echo $count;
                echo "</td>";
                echo "<td>";
                echo $file;
                echo "</td>";
                echo "<td>";
                echo "<input type='submit' value='Download'/>";
                echo "</td>";
                echo "<td>";
                echo "<input type='submit' value='Delete'/>";
                echo "</td>";
                echo "<td>";
                echo "<input type='submit' value='Rename'/>";
                echo "</td>";
                echo "</tr>";
            }
            $count++;
        }
    ?>
</table>
</body>
</html>

enter image description here

I am able to list files but I can't get the "download" and "delete" buttons to work properly.

Any help is greatly appreciated and thank you very much in advance.

  • 写回答

1条回答 默认 最新

  • douzuizhuo0587 2016-08-13 14:18
    关注

    Look at my code

    <html>
    <head>
        <title>My first PHP Page</title>
    </head>
    
    <body>
        <iframe id="my_iframe" style="display:none;"></iframe>
        <table border="1">
        <?php
            $dir = 'uploads';
            $files = scandir($dir);
            sort($files);
            $count = -1 ;
            foreach ($files as $file) {
            $v_download = "download_".$count;
            $v_delete = "delete_".$count;
            $v_rename = "rename_".$count;
                if ($file != '.' && $file != '..') {
                    $str_URL = "uploads".$file;
                    echo "<tr>";
                    echo "<td>";
                    echo $count;
                    echo "</td>";
                    echo "<td>";
                    echo $file;
                    echo "</td>";
                    echo "<td>";
                    echo "<form action='' method='post'><input type='submit' value='Download' name='".$v_download."'/></form>";
                    if(isset($_POST[$v_download])) {
                    // Your php download code here
                    echo "download file : ".$file;
                    }
                    echo "</td>";
                    echo "<td>";
                    echo "<form action='' method='post'><input type='submit' value='Delete' name='".$v_delete."'/></form>";
                    if(isset($_POST[$v_delete])) {
                    // Your php delete code here
                    echo "delete file : ".$file;
                    }
                    echo "</td>";
                    echo "<td>";
                    echo "<form action='' method='post'><input type='submit' value='Rename' name='".$v_rename."'/></form>";
                    if(isset($_POST[$v_rename])) {
                    // Your php rename code here
                    echo "rename file : ".$file;
                    }
                    echo "</td>";
                    echo "</tr>";
                }
                $count++;
            }
        ?>
    </table>
    </body>
    </html>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。