download file, then redirect when download complete

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DavidS
Forum Newbie
Posts: 1
Joined: Fri Oct 01, 2004 6:26 pm

download file, then redirect when download complete

Post by DavidS »

nigma | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color] 

I want to download a file. When the download completes, I would like to redirect to a new page.

I get the download to work OK, but nothing after the fpassthru() executes. I've tried several methods of redirect, but none work following a fpassthru() (Although they work if I remove the download code).

Code: Select all

<?php

$path='../cgi-bin/';
$file='regcode';

$size = filesize($path.$file);
$ext = explode(".", $file);
$type = "application/octet-stream";

header("Content-Type: $type\n");
header("Content-Length: $size\n");
header("Content-Disposition: attachment; filename="$file"\n");
header("Content-Description: Download\n");

$contents = fopen($path.$file,'rb');

/*
downloads file OK
*/
fpassthru($contents);

/*
does not execute
*/
passthru("/index.html");

?>
--------

Can anyone show me a way to do this?

Thanks.

nigma | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Everything after fpassthru() will not be executed. You should try altering your code a little.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

[php_man]readfile[/php_man]()
Post Reply