下载.zip文件运行损坏的文件php
我正在尝试强制下载受保护的zip文件(我不希望人们在没有先登录的情况下访问它。
我有为等创建函数,但我遇到了下载的文件损坏的问题。login
这是我的代码:
$file='../downloads/'.$filename;
header("Content-type: application/zip;\n");
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize($file).";\n");
header("Content-disposition: attachment; filename=\"".basename($file)."\"");
readfile("$file");
exit();
这是错误:Cannot open file: It does not appear to be a valid archive.
否则文件下载正常,所以它一定是我在标题上做错了什么。
有什么想法吗?