Jump to content

Output to download


tbarnette70

Recommended Posts

I'd like to write comma delimited output, and then tell the browser to treat it as a downloaded file instead of browser output.  So that Excel or open office could pop-up.

 

So, the browser would write:

1,2,3,4 as test.csv

 

Then excel or open office would pop up with that data.

 

I know I can actually write a file and then through the headers and fread download the file.  Is there a way to do this without actually creating a file on the server, though?

 

If I HAVE to write a file, has anybody done this with a CSV?

 

Thanks In Advance!

Link to comment
https://forums.phpfreaks.com/topic/158516-output-to-download/
Share on other sites

You want to force a download ?

 

Use that :

<?php
$filename = "something.csv";
$csv = "1,2,3,4
2,3,4,5
3,4,5,6";

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$filename);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . strlen($csv));    

echo $csv;
?>

Link to comment
https://forums.phpfreaks.com/topic/158516-output-to-download/#findComment-836015
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.