Page 1 of 1

header attachment - partial file in IE7 and FF

Posted: Tue Jun 05, 2007 11:52 am
by Silo
The code below is for a page that is attempting to download a set of results to a rtf file. It works fine, but only in IE6. IE7 and Firefox are causing the file to partially transfer. Word gives me a corrupt file error presumably due to the rtf footer not making it in at the end. I'd say about 75% of the data usually makes it into the file.

Code: Select all

$tempdest="/var/www/html/sysrep/reports/$date/$system/$customer/$report";
if (file_exists($tempdest))
{
        $expanded = implode("",@gzfile($tempdest));
        $firstpagebreak=strpos($expanded,chr(12));
        $expanded = substr($expanded,$firstpagebreak+1);
        $expanded = str_replace("\n","\n\\par ",$expanded);
        $expanded = str_replace(chr(12),"\\page ",$expanded);
        header("Content-Descrption: File Transfer");
        header("Content-Type: application/force-download");
        header("Content-Length: ". strlen($expanded));
        header("Content-Disposition: attachment; filename=\"".$_GET["report"].".rtf\"");
        readfile("rtfhead.inc");
        echo $expanded;
        readfile("rtffoot.inc");
}else{
  echo "I have no reports for the information provided. Please try again.<br>\n";
}
exit;
?>
Can anyone help me out with what I'm missing here? Am I not correctly declaring the length/size of the file or something?

Any help is greatly appreciated. I exhausted Google with every possible combination of terms I could think of to figure this out.

Posted: Tue Jun 05, 2007 12:05 pm
by volka
Silo wrote:header("Content-Length: ". strlen($expanded));
you would send strlen($expanded) bytes with
echo $expanded;
but you are sending
readfile("rtfhead.inc");
echo $expanded;
readfile("rtffoot.inc");
and unless rtfhead.inc and rtffoot.inc are empty that's more data.

Posted: Tue Jun 05, 2007 12:21 pm
by Silo
Ahh, well that certainly makes sense. Sometimes it just takes another person to look at it and show me what I keep overlooking.

I'm curious as to why IE6 still transfers the entire file, though...

Posted: Tue Jun 05, 2007 1:39 pm
by feyd
IE6 pretty much ignores the header if it goes longer. It's even more dumb than IE7.