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

Home » Imported messages » comp.lang.php » Pls help with output of csv file to browser?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Pls help with output of csv file to browser? [message #179283 is a reply to message #179280] Sun, 30 September 2012 17:01 Go to previous messageGo to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma:
Senior Member
BobMCT wrote:
^^^^^^
Who?

> I'm trying to add the generation of a csv file to send to the
> requestor's browser. So far I do have it working (sort of) by sending
> special headers indicating a text file and using fputcsv. The user
> receives the expected what to do prompt and if saved the dialog box
> asking where to save it appears and works.
>
> That's the good part.
>
> The bad part is that there is no resulting/completion page.

There is not supposed to be one. The moment the download starts, control is
turned over to the client which hopefully (and usually) provides the feature
to show the progress of the download.

> And, if I examine the saved csv file it actually contains the html for
> the subsequent page and the originating page still resides on the
> requestor's screen.

That is BAD. Borken As Designed.

> My guess would be that once the file is sent another set of header
> details must be sent to tell the browser that html is now coming.
> But, I cannot locate any examples of what to send in this case.
>
> I'm hoping that some of you readers have done this before and can
> share the technique/mechanism used to accomplish this successfully.
>
> Any ideas/examples/suggestions greatly appreciated.

It should be possible to send an HTTP multi-part response message as defined
in <http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7.2>.
However, since that might not be supported, you should include a link for
downloading *only* the CSV in the HTML part anyway.

That is, if you absolutely must display an HTML document along with the CSV
download. The simpler way is not so send any HTTP response containing
*HTML* on success at all, for example:

<?php
/* process data */

if ($success)
{
header('Content-Type: text/csv; charset=UTF-8');
header('Content-Disposition: attachment; filename=my.csv');
fputcsv('php://stdout', …);
}
else
{
header('Content-Type: text/html; charset=UTF-8');
require_once 'error.php';
}
?>

You may also use, but should never rely on, client-side processing.


PointedEars
--
When all you know is jQuery, every problem looks $(olvable).
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: FEDEX Shipping
Next Topic: Asynchronous execution of PHP file
Goto Forum:
  

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

Current Time: Sun Nov 10 06:14:37 GMT 2024

Total time taken to generate the page: 0.05651 seconds