请多个文件强制下载 [英] Make multiple files to force-download

查看:90
本文介绍了请多个文件强制下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,如果标题没有太多解释。让我尝试进一步解释。

我有code,看起来像这样:

 &LT ;?
//抢count.txt数
$数= INTVAL(的file_get_contents('count.txt'));
//移动的号码上移一个
的file_put_contents('count.txt',$ ++计数);
$数=的file_get_contents('count.txt');
//强制下载
标题(内容处置:附件;文件名=数据文件'$号。CSV);
标题(内容类型:应用程序/八位字节流);//数据的foreach($数组作为$资讯){
回声$资讯\\ n。
}
?>

使用$阵列作为数据的数组。

现在有时数据量可以比5000以上,所以,如果数据是超过5000,使为正在呼应每5000个数据的另一个文件。 EA:如果有20,000个数据的$阵列中,那么它将做出一个总的4个文件


解决方案

您不能在响应HTTP请求发送超过1文件。

我的建议被压缩在一个文件中的文件,并返回。

请参阅:下载多个文件,在PHP

Sorry if the title doesn't explain much. Let me try to explain further.

I have code that looks like this:

<?
//Grab the number in count.txt
$count = intval(file_get_contents('count.txt'));
//Move the number up one
file_put_contents('count.txt', ++$count);
$number = file_get_contents('count.txt');
//Force Download
header('Content-Disposition: attachment; filename=DataFiles'.$number.".csv");
header('Content-Type: application/octet-stream');

//The data

foreach($array as $info){
echo $info."\n";
}
?>

With $array being an array of data.

Now sometimes the amount of data can be more than 5000, so if the data is over 5000, make another file for every 5000 data that is being echoed. Ea: If there is 20,000 pieces of data in the $array, then it will make a total of 4 files.

解决方案

You cannot send more than 1 file in response to an HTTP request.

What I would suggest is zip the file in a single file and return that.

See: download multiple files as zip in php

这篇关于请多个文件强制下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆