Page 1 of 1

download file, then redirect when download complete

Posted: Fri Oct 01, 2004 6:27 pm
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]

Posted: Fri Oct 01, 2004 7:24 pm
by Joe
Everything after fpassthru() will not be executed. You should try altering your code a little.

Posted: Fri Oct 01, 2004 7:46 pm
by feyd
[php_man]readfile[/php_man]()