Apr 27 2010

Correct headers to download a CSV from PHP

Category: PhpGiulio Pons @ 11:40 am

With these headers you can force a download from php, for example, to let the user download a csv frmatted text.
To make all the thing works you have to print data with “tabs” char, even if csv means “comma separeted value”. This is necessary because Microsoft Excel will understand tabs, but not commas.

header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"yourfilename.xls\"");
/*
      here print rows with values separeted by tab char: "\t"
*/
Share

Related posts:

  1. Reading mp3 informations with php (id3 tags)
  2. Fix html tags, close tags, repair bad quotes and more
  3. Tiny url encode and decode with PHP

Tags: , , , , ,

Leave a Reply