【问题标题】:PHP download, delete and rename files with buttonsPHP 使用按钮下载、删除和重命名文件
【发布时间】:2016-12-20 07:42:40
【问题描述】:

所以我正在使用 php 创建一个小型文件管理器,它将在表格中列出我服务器上一个目录中的所有可用文件,并为我提供下载或删除选项。

这是我的代码:

<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>

我可以列出文件,但无法让“下载”和“删除”按钮正常工作。

非常感谢任何帮助,并在此先感谢您。

【问题讨论】:

  • 你在使用提交吗?你的表格在哪里

标签: php html list file directory


【解决方案1】:

看我的代码

<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>

【讨论】:

    猜你喜欢
    • 2012-02-13
    • 2015-03-09
    • 1970-01-01
    • 2014-03-04
    • 2021-12-22
    • 2023-03-14
    • 2018-10-30
    • 2017-03-05
    • 2014-06-06
    相关资源
    最近更新 更多