And*_*rew 1 php arrays fopen output
我想将我的数据输出到一个文件供用户下载,而无需在服务器上实际创建文件.该文件的数据就是我正在转换为CSV格式以供用户下载的数组.这是我的代码:
$fh = fopen('file.csv','w');
fputcsv($fh,$arr); // $arr is my array that contains the data to be parsed into CSV
fclose($out);
Run Code Online (Sandbox Code Playgroud)
上面的代码成功创建了文件...但我不想创建文件.我想简单地输出输出.
任何帮助将不胜感激!
您可以使用
header("Content-type: text/csv");
header("Cache-Control: no-store, no-cache");
header('Content-Disposition: attachment; filename="content.csv"');
...
$file = fopen('php://output','w');
Run Code Online (Sandbox Code Playgroud)