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 #170031 is a reply to message #170026] Wed, 06 October 2010 11:19 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 10/5/2010 11:50 PM, Adam Harvey wrote:
> On Tue, 05 Oct 2010 14:06:45 -0400, sheldonlg wrote:
>> On 10/5/2010 12:52 PM, Derek Turner wrote:
>>> When TB exports a csv it doesn't quote text fields so presumably it
>>> doesn't need them quoted to import them:
>>
>> What if I have in there that my nickname is Shelly ("sheldonlg")? How
>> does the db have the " in the table? How is that retrieved? How does
>> that appear when written to the browser? What if single quotes are used
>> as in O'Reilly? That is what Jerry is talking about. You always have
>> to be concerned with things like this.
>
> Indeed, which is why I'd go with the built-in fputcsv() function which
> should do sensible things with quoting; ie something like this:
>
>
> // fputcsv() can only write to a file/stream handle, so let's open one up.
> $fp = fopen('php://temp', 'r+');
>
> // Loop over the data using whatever the appropriate database function is.
> // We'll assume $rs is a MySQL result resource, but it doesn't really
> // matter where it comes from.
> while ($row = mysql_fetch_array($rs)) {
> fputcsv($fp, $rec);
> }
>
> // Rewind the stream handle and actually output the CSV data.
> // No temporary file required!
> header('Content-Type: text/csv');
> rewind($fp);
> fpassthru($fp);
> fclose($fp);
>
>
> Adam

I wouldn't create a temp file for it. The code to output it directly to
the browser. It's not that hard.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[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 13:34:03 GMT 2024

Total time taken to generate the page: 0.06570 seconds