p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Writing data to a file on the client PC


Message #1 by "Jon Shoreman" <jon.shoreman@b...> on Wed, 2 Oct 2002 15:39:52
I have searched the documentation on www.php.net and cannot find the 
answer to my question.

I want to write data to a CSV file and save the file on the client PC.

When the client clicks on a link, the s/w creates the file and a "Save As" 
box opens.

How do i do this?
Message #2 by "Nikolai Devereaux" <yomama@u...> on Wed, 2 Oct 2002 09:33:34 -0700
It has to do with sending HTTP headers to let the client's browser know that
the incoming data is NOT text/html.

Try something like this:

  $filename = 'yourfile.csv';
  header('Content-Type: text/x-csv');
  header('Content-Disposition: inline; filename=' . $filename);
  header('Expires: 0');
  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  header('Pragma: public');

Now, everything you echo to the browser will be considered text/x-csv output,
not HTML.

take care,

nik

Message #3 by "Jon Shoreman" <jon.shoreman@b...> on Wed, 2 Oct 2002 18:05:45
nik,

you are a star :-)

thanks a lot

jon

  Return to Index