如何在不等待PHP回复的情况下立即创建下载文件

时间:2014-05-29 01:11:44

标签: php html html5 http-headers

我使用新标记<a download="test.csv" href="exp.php?type=5">而我的exp.php需要一些时间来计算结果。我希望文件能够显示海峡,并在加载/生成时添加数据。

我尝试了这些,但他们不工作:

// Required
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment;');

// Experimental
header('Content-Transfer-Encoding: binary');
header('Content-Type: application/octet-stream');
header('Pragma: public');
header('Connection: close');

// ... exp.php
$output = fopen('php://output', 'w');
fputcsv($output, $example); // Runs ~ 100-2000 times (10-5000 seconds)

0 个答案:

没有答案