【发布时间】:2023-04-10 09:00:03
【问题描述】:
我想下载一个 .zip 文件,但是当我去下载它时,它迫使我下载 .php 文件。我使用这个遍布互联网的简单代码,所以我不知道为什么我不能下载 .zip 文件。
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Content-type: application/zip");
header('Content-length: '.filesize($fullpath));
header("Content-disposition: attachment; filename=".basename($fullpath));
readfile($fullpath);
【问题讨论】:
-
你用哪个浏览器测试它?
-
您确定您不只是下载一个名为 .php 的 zip 文件吗?
-
你不需要
filesize($fullfile)吗? -
我在 readfile() 中使用了完整路径,现在改了
-
你的代码现在对我来说工作得很好。