1

File resource - fopen('php://output')

Header list:

Content-Type: application/csv
Content-Disposition: attachment; filename="test.csv"
Cache-Control: max-age=0
Expires: 0
Cache-Control: must-revalidate
Pragma: public

How i download:

ob_clean();
readfile("php://output");
exit;

ob_get_contents() before readfile is not empty and data which i write to file too.

But loaded file is empty. Why

1 Answers1

1

https://www.php.net/manual/en/wrappers.php.php#wrappers.php.output

Says:

php://output is a write-only stream that allows you to write to the output buffer mechanism in the same way as print and echo.

You're trying to read from it, which clearly cannot be done.

It is unclear to me what you're actually trying to achieve.

KIKO Software
  • 15,283
  • 3
  • 18
  • 33
  • Thanks. It leads me on some idea. I just replcae `ob_clean` on `flush` and it is works. But i cant absolutely recognize. If flush drop the buffer too, even so readfile works good. I mean if buffer droped then , i guess, php://output should be empty and readfile wont work. But it is no so and file is loaded correctly with some data. – Nikita Karpenko Apr 29 '20 at 11:58