Forum Moderators: coopster

Message Too Old, No Replies

How to refresh page

once the headers have been sent

         

Wayder

10:26 pm on Sep 19, 2014 (gmt 0)

10+ Year Member Top Contributors Of The Month



I have created my csv file and downloaded it.

$strtoexport = ‘lots,of,lovely,comma,delimited,stuff’;
header("Cache-Control: must-revalidate, post=check=0, pre-check=0");
header("Content-Length: " . strlen($strtoexport));
header("Content-type: textx-csv");
header("Content-Disposition: attachment; filename=myfile.csv");
echo $strtoexport;

Now I need to continue the script but it has stopped because the file has been sent. How can I get it to continue?

I was thinking of placing the download in an external file to work separately but I'm a bit stuck on how I an do that as pcntl_fork() is not available to me.

What I need is for the file to download and the page to continue. It needs to do that as the content is based on the information that has been altered by the download. eg 100 widgets have been downloaded (now 101).

Any ideas please.

Thanks

Wayder

12:31 am on Sep 20, 2014 (gmt 0)

10+ Year Member Top Contributors Of The Month



Done. I saved the file, reloaded the page with a 0 delay meta refresh to call /download.php that reads the file and outputs the header to download the file.

incrediBILL

1:09 am on Sep 20, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Clever.

Another method would be to use a little simple javascript and create the file and download it via AJAX and bypass messy reloads and other such things.

Wayder

10:47 pm on Sep 22, 2014 (gmt 0)

10+ Year Member Top Contributors Of The Month



Sorry I'm a bit late in replying.

I can't take credit for this, it was about the 100th search variation that gave me the solution, I just wrote the code.

I added a link that says your download will start shortly, but you can click here if you dont want to wait. for when the refresh doesnt happen.

I agree with the AJAX solution, but personal preference made me discard this at the beginning.

Thanks for the suggestion though.