Page 1 of 1
Redirect after force download
Posted: Wed Apr 13, 2011 12:27 pm
by gkjr1
I have a force download, which uses headers obviously so I can't redirect with a header in the script. It pops the download up on the page, but I need the page to either refresh or redirect after download has started. Ive tried putting headers in the form for the download, tried in the force download in the code regardless, tried java and a header in the force download code, but am stuck. Any ideas?
Re: Redirect after force download
Posted: Thu Apr 14, 2011 3:08 pm
by gkjr1
Sorry for this, im just kinda stuck here. Still have nothing working...
Re: Redirect after force download
Posted: Thu Apr 14, 2011 6:47 pm
by McInfo
Do the reverse. Have the confirmation page trigger the download. For example, suppose a visitor requests confirm.php.
confirm.php
Code: Select all
<!DOCTYPE html>
<html>
<head>
<title>Confirmation</title>
<meta http-equiv="refresh" content="0;url=http://localhost/download.php" />
</head>
<body>
<p>Your download should have begun. If not, try <a href="http://localhost/download.php">download.php</a>.</p>
</body>
</html>
The meta tag tells the visitor's browser to request download.php.
download.php
Code: Select all
<?php
header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename=example.txt');
echo 'Example';
Because download.php specifies that it should be downloaded as an attachment, the visitor's browser stays on confirm.php while downloading the file.
Re: Redirect after force download
Posted: Sat Apr 16, 2011 10:23 pm
by gkjr1
mmm thanks! Can't believe that logic slipped my mind.