I am using this little pusher php file to download an ‘exe’ file for the user to save when they fill-out a form.
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
with this method there is no link to the online $file location for someone to follow but for some reason I cannot display a thank you page after or even immediately before the code is executed.
I’ve tried header( “Location: $thankyouurl” ); immediately after the above code, but nothing is ever displayed and I’ve tried echoing the html source of the thank you page just prior to running the above code, but that causes the exe file to be downloaded to the web page actually crashing the browser.
Any suggestions???
Point the user directly to a static page that displays your thank you message. Then, use JavaScript to set the
window.locationto your download script.If your download page’s headers are set up correctly, the browser will start downloading the file, while your user is reading your thank you message.
Make sure to display a direct download link in case the user has JavaScript disabled.
Example:
index.php
thankyou.php
download.php
Update
In order to pass data from
index.phpon to the download script, you could useGETvariables. The link to thethankyou.phppage would becomethankyou.php?download=12where download is an ID for you to grab the correct file. You would then pass that variable on to your download script by echoing it out in your markup like so:index.php
thankyou.php
You’d then grab the value in your download script and handle it any way you like.