Copy link to clipboard
Copied
I posted this question yesterday but for some reason it isn't showing up on the forum, so I'm reposting.
I have a small php file to force a download when a user clicks on a link:
<?php
header ("Content-type:application/pdf");
header ("Content-Disposition:attachment;filename='form.pdf'");
readfile ("form.pdf");
?>
I need to add code to this script which will automatically redirect the user to the home page within the same browser window, either during or immediately after the file downloads. And if it is possible, prevent the browser back button from returning the user back to the page that contains the download link.
I tried adding this after the readfile line: echo "<a href="mywebsite.com/index.html" /a>";
But that failed miserably, a monument to my limited php skills. Can someone help me out?
Copy link to clipboard
Copied
Oops, my bad. My original message is now showing
on the board. Sorry about the double post. Now if I can just get someone to answer... ![]()
Copy link to clipboard
Copied
You can do this in PHP:
header ("Location: redirectToHere.html");
Not sure how to disable the back button.
Nick
Copy link to clipboard
Copied
Hi Nick
Thanks for your suggestion! I tried adding that header line, substituting the full path to index.html in place of redirectToHere. When I placed it after the readfile line in my script, the file downloaded normally but the browser page wasn't redirected. Then I tried putting your header line with the other header lines above readfile, but when clicking on the link, the file does not download and instead I get an error 404 Page not found. Am I missing something?
Copy link to clipboard
Copied
Hmm... when you call the readfile() it opens the file that you link to. The location is then set to that, so you can't redirect.
Is there another way you could download the file? I'm afraid I've gone slightly beyond my PHP knowledge. Sorry.
Nick
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more