Hi,

I'm having a problem with redirecting (Location: script.cgi) after a file has been downloaded.

Here is the gist of the script. It creates two files (one html, the other text), then a download dialog box comes up so the first newly created file can be saved. But after the file is saved, I'm trying to call the script again to download the second file, as I can't seem to get the second file to download after the first one has finished. But all I am getting is the first file downloaded with the 'print "Location: script.cgi?text\n\n"' at the bottom of the saved file. Do I need to change the Content-type or something to be able to call the script again? Here is a sample of the script.

Any ideas would be very helpful. Thanks very much,

Mark
------------------------------------------------------------------------ -

<CODE>

my $request = $ENV{'QUERY_STRING'};
if ($request eq "text") { &save_text; exit; }

# Create the files
.
.
.
#===========================
# Save HTML version
#===========================

&save_file($htmlname);

print "Location: script.cgi?text\n\n";

exit;

#===========================
# Save TEXT version
#===========================

sub save_text {

&save_file($textname);

print "Content-type: text/html\n\n";

print "finished.";

exit;

}

#===========================
# Save files
#===========================

sub save_file {

my $path = "$pathtofile$_[0]";
my $filename = $_[0];
my $size = (stat($path))[7]; # the size, in bytes
binmode STDOUT;

print "Content-Length: $size\n";
print "Content-Disposition: attachment;filename=$filename\n";
print "Content-Type: application/octet-stream\n\n";

open (FILE, "< $path") || die("Can't open($filename): $!");
binmode(FILE);

my $data;
while(read(FILE,$data,4096)) {
        print $data;
}
close(FILE);

}

</CODE>

Reply via email to