gpt4 book ai didi

php - 在foreach循环问题中下载多个文件

转载 作者:行者123 更新时间:2023-12-04 00:07:08 25 4
gpt4 key购买 nike

我有如下代码通过代码下载一些日志文件

$files = array( '../tmp/logs/debug.log',
'../tmp/logs/error.log');
foreach($files as $file) {
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: text/html");
header("Content-Transfer-Encoding: binary");
// read the file from disk
readfile($file);
}

但只下载数组的第一个元素。在这种情况下 debug.log ,如果我交换元素,那么只有 error.log。有什么帮助吗?

最佳答案

每个 HTTP 请求只能下载一个文件。实际上,一旦发送了第一个文件,浏览器就会认为处理结束并停止与服务器通信。

如果您想确保用户下载多个文件,一种解决方案可能是在服务器端即时压缩所有文件,然后将压缩文件发送给用户进行下载。

关于php - 在foreach循环问题中下载多个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36885750/

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