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 #170026 is a reply to message #170021] Wed, 06 October 2010 03:50 Go to previous messageGo to previous message
Adam Harvey is currently offline  Adam Harvey
Messages: 25
Registered: September 2010
Karma:
Junior Member
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
[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 15:41:05 GMT 2024

Total time taken to generate the page: 0.04931 seconds