我正在尝试使用将CSV加载到PHP数组,然后对其进行处理,并将该过程的结果输出到html文件中,该文件将立即下载。我已经完成了读入和处理的工作,但是无法使下载工作。我找到了https://www.php.net/manual/en/function.readfile.php,但是所有示例都显示了创建文件然后下载的过程,我可以将缓冲区中的HTML代码直接写入download.html文件吗?任何帮助表示赞赏。马库斯
喜欢这个,你可以做:
<?php
$html_string.="<h1>This is your form</h1>";
foreach ($_POST as $p=>$value) $html_string.="{$p} has {$value}";
header('Content-Disposition: attachment; filename="readme.html"');
// other header() calls you need
die($html_string);
?>
或
$f = fopen("tmp.csv", "w");
foreach ($array as $line) {
fputcsv($f, $line)
}
header('Content-Disposition: attachment; filename="filename.csv";');