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

First off, the Location field *must* be an absolute URL, it is not allowed to be a relative URL (so says the specification).

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.

You cannot respond to a single request from the browser with two responses (one for the first file and one the Location redirect). If you could, you would not need to do what you're doing, you would be able to respond with two responses, one for each file.

You could possibly return two files by sending a multipart response containing both files. I've never tried this myself, or even ever seen this done, but it might be possible.

Obviously, what you could do is return a web page with two links and get the user to click both to download both files.

But then again, maybe I'm misunderstanding what you're trying to do.
   Peter.



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>


--
<http://www.stairways.com/>  <http://download.stairways.com/>

Reply via email to