php - PHP; 将 CSV 导出到输出缓冲区:加载的文件为空。为什么?
问题描述
文件资源-fopen('php://output')
标题列表:
Content-Type: application/csv
Content-Disposition: attachment; filename="test.csv"
Cache-Control: max-age=0
Expires: 0
Cache-Control: must-revalidate
Pragma: public
我如何下载:
ob_clean();
readfile("php://output");
exit;
readfile 之前的 ob_get_contents() 不为空,并且我也写入文件的数据。
但是加载的文件是空的。为什么
解决方案
https://www.php.net/manual/en/wrappers.php.php#wrappers.php.output
说:
php://output
是一个只写流,允许您以与print和echo相同的方式写入输出缓冲区机制。
你正试图从中读取,这显然是做不到的。
我不清楚你实际上想要达到什么目的。
推荐阅读
- python - 从数据框的不同列显示堆积条形图的每种颜色的值
- node.js - pg-promise 将整数读取为字符串,即使在被解析之后也是如此
- sql - SQL中的左右连接
- node.js - Angular 5 - ag-grid 18.0.1 - 边缘崩溃
- ios - 向下滚动(或从 ipad 更改为 iphone 时)的 TableViewCell 边框和阴影
- vba - 根据条件查找范围内最常用的文本
- django - 发出 img 请求时出现跨域读取阻塞 (CORB) 问题
- java - 扩展可比较的 Java 泛型类不能转换为 java.base/[Ljava.lang.Comparable
- c# - UnityContainer 抛出空引用异常
- prolog - 使用数据库迭代关系