gpt4 book ai didi

php - 打开下载的 zip 文件会创建 cpgz 文件吗?

转载 作者:可可西里 更新时间:2023-10-31 23:05:08 26 4
gpt4 key购买 nike

如果我将 zip 文件的 url 设置为链接的 href 并单击该链接,我的 zip 文件将被下载并打开它并获得我预期的内容。

这是 HTML:

<a href="http://mysite.com/uploads/my-archive.zip">download zip</a>

问题是我希望链接指向我的应用程序,以便我可以确定用户是否有权访问此 zip 文件。

所以我希望我的 HTML 是这样的:

 <a href="/canDownload">download zip</a> 

还有我的 /canDownload 页面的 PHP:

//business logic to determine if user can download

if($yesCanDownload){

$archive='https://mysite.com/uploads/my-archive.zip';
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=".basename($archive));
header("Content-Length: ".filesize($archive));
ob_clean();
flush();
echo readfile("$archive");
}

所以,我认为问题与 header() 代码有关,但我已经根据各种谷歌和其他 SO 建议尝试了很多与之相关的事情,但都没有用。

如果您回答了我的问题,您很可能也可以回答这个问题:Zipped file with PHP results in cpgz file after extraction

最佳答案

我的答案是在 readfile() 之前输出了一个空行。

所以我补充说:

ob_end_clean();

readfile($filename);

但是您可能应该在代码中搜索输出该行的位置。

关于php - 打开下载的 zip 文件会创建 cpgz 文件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11495103/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com