NYCPHP Meetup

NYPHP.org

[nycphp-talk] Re: Downloading a CSV file

Brian Pang bpang at bpang.com
Tue Sep 7 23:43:24 EDT 2004


Instead of streaming the results, you could instead write the output to
a static file and then push that back to the browser. You'd have to do
similar header() settings.
Similar approach and may work a little better for large datasets.
But for 50 Jeff's approach is solid.

Sometimes, I will actually return html tables (and call the file
foo.xls) instead of csv, but, of course, the file gets to be
significantly larger with all those tags.



> On 07/09/04 23:04 -0400, Jeff Siegel wrote:
> > Here's some pseudo code to get you started. It should prompt the user 
> > with a dialog box to save the file. 
> 
> That's what I'm looking to do!
> 
> > However, keep in mind that if you 
> > have really large datasets (40,000 rows+) this may not work
> 
> I was thinking more along the lines of 50 rows. :-)
> 
> > Header("Content-type: text/csv\n",true);
> > Header("Content-Disposition: attachment;
filename=myfilename.csv",true); 
> > 
> > Header("Pragma: no-cache",true);
> > Header("Expires: 0",true);
> > print $csv_output;
> > exit;	
> 
> That's it!  Thanks!
> 
> 
> -- 
>  
> Regards,
>  
> Faber                     
> 
> Linux New Jersey: Open Source Solutions for New Jersey
> http://www.linuxnj.com
> 
> 
> 
> _______________________________________________
> New York PHP Talk
> Supporting AMP Technology (Apache/MySQL/PHP)
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.newyorkphp.org
> 
> 





More information about the talk mailing list