PHP使scandir结果文件可下载

时间:2016-12-26 12:11:37

标签: php

我做了一个特定目录的scandir,我在表格中显示文件名。现在我想让每个文件都可以下载,但我不知道该怎么做。

这是我在表格中打印文件名的地方:

<tbody>
            <?php
                $i = 0;
                foreach ($files as $file) {
                    $i++;
                    echo "<tr><th scope='row'>$i</th><td>$file</td><td><i class=\"fa fa-download\" aria-hidden=\"true\"></i></td></tr>";
                }
            ?>
</tbody>

我正在考虑使用类似这样的函数或php文件

header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=file.zip");
header("Pragma: no-cache");
header("Expires: 0");
readfile("file.zip");

但我不知道如何在我的php文件函数中注入文件名和内容类型

非常感谢任何帮助!

非常感谢提前!

0 个答案:

没有答案
相关问题