FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Send .csv file to browser
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Send .csv file to browser [message #170034 is a reply to message #170003] Wed, 06 October 2010 14:42 Go to previous messageGo to previous message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma:
Senior Member
El 05/10/2010 16:19, Derek Turner escribió/wrote:
> I want to use MySQL to get a list of email addresses and names and then
> output a .csv file to the browser so that it can be saved and then
> imported into Thunderbird etc.
>
> Having googled around I think the solution will be:
>
> 1. Create and open a local file for writing
>
> 2. Write the data to the local file and close it
>
> 3. Use appropriate header files and then readfile()
>
> 4. Delete the local file
>
> Questions:
>
> 1. Is this a reasonable approach? Or should I be outputting to the
> browser on the fly? Or using PEAR or something like that?

The main benefits of generating a temp file are:

1. You don't have to hold the complete file in memory
2. You can reuse the output

However, readfile() loads the whole file into memory and you delete the
file after sending it.


> 2. Can the headers appear appear anywhere in the script or must they be
> be the first lines?

Headers always come first in almost everything (HTTP, e-mail, etc.).
With certain settings, PHP is able to cache regular output until you
send the last header but it normally makes coding a bit more complicate
and, in your case, you probably don't want to echo the complete file
before the download even starts.




--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: file access permission?
Next Topic: Process queue without cron jobs
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 03:35:47 GMT 2024

Total time taken to generate the page: 0.03552 seconds