/    Sign up×
Community /Pin to ProfileBookmark

download and redirect …

Hi, I have this script that downloads a file. Next, I would like an automatic redirect to an other page. The problem is that my redirect command somehow is not read but added to the downloaded file ! Any way to prevent this ??
thanks in advance for your help !

here is my script:

[code=php]$name=’file.txt’;
$add=’http://www.mysite.com/’.$name;

$gogo=”Content-Disposition: attachment; filename=”.$name;

$content_len=@filesize($add);
Header(“Content-type: application/txt”);
Header(“Content-type: octet-stream”);
Header($gogo);
if($content_len!=FALSE)
{
Header(“Content-length: $content_len”);
}
readfile($add);
//the next echo is the problem … it is added to the file!
echo “<script>window.location.href=’mynextpage.php’;</script>”;[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NightShift58Feb 14.2007 — The moment your headers are set as they are, you cannot echo anything to screen, as this will become part of the download.
Copy linkTweet thisAlerts:
@patimagesauthorFeb 14.2007 — how might I redirect then ? Any idea ?
Copy linkTweet thisAlerts:
@hessodreamyFeb 14.2007 — instead of redirecting, how about presenting the confirmation page you would have redirected to, and handle the file download on another script, which you load in an invisible frame or iframe inside your confirmation page?

eg.
<i>
</i>&lt;html&gt;
You should be getting prompted to download a file right now...
&lt;iframe style="display:none" src="filedownloadscript.php"&gt;
&lt;/html&gt;

Would that do what you want?
×

Success!

Help @patimages spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...