Path: csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: bill Newsgroups: comp.lang.php Subject: Re: Pls help with output of csv file to browser? Date: Mon, 01 Oct 2012 08:16:44 -0400 Organization: Aioe.org NNTP Server Lines: 43 Message-ID: References: NNTP-Posting-Host: 3qER3ivYp3VzEuZD7C/pcg.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.php:7215 On 9/30/2012 11:19 AM, BobMCT wrote: > 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. 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. > > 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. > > Thank > What I do (which is not a recommendation ;-) is: using javascript I have the originating page (the page before the output): 1. the button (or whatever) opens a new page, using window.open('new_script.php?args_as_necessary') 2. then submits the window.open invokes new_script.php that actually generates the csv and send it with the appropriate headers. Firefox will put the csv in a new tab on top. the submit of the originating page generates and sends the subsequent page (which probably will be under the csv) the user saves/prints the csv and closes that tab and the subsequent page pops up. Yeah it requires javascript, not a problem in my setting (intranet).