Posted by Janwillem Borleffs on 10/10/21 11:24
Mark C wrote:
> I admit the subject is a bit of an oxymoron. Here is what I want to
> do:
>
> I want to build a CSV file in a variable and then redirect the
> browser to the contents of the variable so the user can download the
> "file" or open it in Excel. I don't want to create a real file so I
> can avoid cleaning up files after they are used.
>
> Is there a way to do this? I'm using Php on Linux.
>
Just redirect to a file which gathers the data and sends the apprioriate
headers to the browser to trigger the download dialogue.
Example:
// download.php
<?php
// Headers to start the download; note that a timestamp is used
// as the file name to prevent caching
header('Content-Type: x-download');
header('Content-Disposition: attachment; filename="' . time() . '.csv"');
// Construct and echo the data here
?>
JW
Navigation:
[Reply to this message]
|