gpt4 book ai didi

php - 制作多个文件强制下载

转载 作者:可可西里 更新时间:2023-11-01 13:03:36 24 4
gpt4 key购买 nike

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

我有这样的代码:

<?
//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";
}
?>

$array 是一个数据数组。

现在有时数据量会超过5000条,所以如果数据超过5000条,就每回显5000条数据再建一个文件。 Ea:如果$array中有20000条数据,那么一共会生成4个文件。

最佳答案

这里是如何下载多个文件...诀窍是在同一页面中呈现多个 iframe。每一帧都有不同的源,强制下载不同的文件

<?php
for($i = 0; $i<5; $i++){
echo '<iframe src="test_multiple_downfile.php?text='.$i.'">/iframe>';
}
?>

test_multiple_downfile.php 内容是这样的:

$out = $_GET['text'];
header("Content-Type: plain/text");
header("Content-Disposition: Attachment; filename=testfile_".$out.".txt");
header("Pragma: no-cache");
echo "$out";

关于php - 制作多个文件强制下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16390601/

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