Jump to content

Recommended Posts

Not sure what is going on, please help me.

I have written a PHP file that generates a CSV file that is drawn from a MySQL database. This works just fine because I used this https://stackoverflow.com/questions/15769732/write-to-php-output-buffer-and-then-download-csv-from-buffer as a guideline.

The problem is this: After the CSV file is downloaded, I want the site to go to another page. Using the code in the reply from DigiLive on 12 Jan 2016 as the basis, after the line

ob_end_flush();

I have the lines

echo "<script type='text/javascript'> document.location = 'OtherPage.php'; </script>";
exit;

These lines work perfectly elsewhere, but here they do nothing. What am I missing?

Link to comment
https://forums.phpfreaks.com/topic/314913-what-am-i-missing/
Share on other sites

29 minutes ago, groston said:

I have the lines

 

29 minutes ago, groston said:

but here they do nothing

actually, they are being appended to the end of the downloaded file. if you open the downloaded file in your programming editor, you should see that output. in the 'other' cases where you may have used those lines of code and they worked, you weren't downloading files, where you?

the response that the web server outputs for a downloaded file - the http headers, followed by the file contents, can only be those two things.

short-answer: you cannot redirect after the file download.

if you do a web search on this, you will find that you first goto the desired final page, then use javascript on that page to make a http(s) request to the download link.

Link to comment
https://forums.phpfreaks.com/topic/314913-what-am-i-missing/#findComment-1597190
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.