Click to See Complete Forum and Search --> : Continue execution after download headers


tbirnseth
10-06-2006, 02:20 AM
I'm downloading some files to user's computers. I use the following routines to send a stream. Execution of the page stops after the download. I.e. I can't get to the next header("Location: blah blah"); without a refresh.

I'm not a header guru so hoping someone can tell me if one of these is getting me stuck!

Thanks in advance for any help,
tony



function whichBrowser() {

$browser=$_SERVER['HTTP_USER_AGENT'];

if(ereg('Opera(/| )([0-9].[0-9]{1,2})', $browser)) {
return 'OPERA';
} else if(ereg('MSIE ([0-9].[0-9]{1,2})', $browser)) {
return 'IE';
} else if(ereg('OmniWeb/([0-9].[0-9]{1,2})', $browser)) {
return 'OMNIWEB';
} else if(ereg('(Konqueror/)(.*)', $browser)) {
return 'KONQUEROR';
} else if(ereg('Mozilla/([0-9].[0-9]{1,2})', $browser)) {
return 'MOZILLA';
} else {
return 'OTHER';
}
}

function sendStream($str, $type, $filenameHint='upsImport') {
$browser = whichBrowser();
if( !$filenameHint )
$filenameHint = "YourFile";

switch ($type) {
case "exe": (($browser=='IE' || $browser=='OPERA')? ($ctype="application/octetstream"):($ctype="application/octet-stream"));
break;
case "pdf": $ctype="application/pdf";
break;
case "zip": $ctype="application/zip";
break;
case "doc": $ctype="application/msword";
break;
case "xls": $ctype="application/vnd.ms-excel";
break;
case "ppt": $ctype="application/vnd.ms-powerpoint";
break;
case "gif": $ctype="image/gif";
break;
case "png": $ctype="image/png";
break;
case "jpe": case "jpeg":
case "jpg": $ctype="image/jpg";
break;
case "csv": $ctype="text/text";
break;
default: $ctype="application/force-download";
}

header("Pragma: public");
header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: $ctype");
header('Content-Disposition: attachment; filename="'.$filenameHint.'.'.$type.'"');
header("Content-Transfer-Encoding: binary");
header('Content-Length: '.strlen($str));
set_time_limit(0);
echo $str;
}

netbuddy
10-06-2006, 02:43 PM
dont know if this has anything to do with it... header("Content-Transfer-Encoding: binary"); but some files need to be transfered as binary, but others need to be ascii.

IM not too sure on headers myself as I have encountered a problem recently with them.

tbirnseth
10-06-2006, 03:03 PM
That's what the switch is there to determine. The actual file is a csv file so it's all text. Guess I can give them another button on the page to go to the next step or something. But like to understand "why"! :)