robgudgeon
asked on
outputting to browser after sending binary file
Hi
Using code from this site, I've managed to create a CGI that will send a binary file to a user. My question is: after the header has been sent, can I write to the browser anymore?
My code essentially looks like this:
elsif ($q->param('download')) {
my $file = "../htdocs/HKBeta.exe";
my @stats = stat($file);
$|++; # Disable output buffering
my $nl=$/; # Save the newline character
undef $/;
open(F,$file) || die $!;
binmode(F); # Open the file in binary mode
my $file_contents=<F>; # Read the entire file into a single variable
close(F);
$/=$nl; # Restore the newline character
print header( -type => 'application/octet-stream' ,
-Content_Disposition => 'attachment; filename=HKBeta.exe',
-Content_Length => $stats[7],
);
print $file_contents;
print "<p>** hello. testing.....";
display_footer();
Clicking the download button causes the save-as window to popup but I can't do anything after this - should this be possible?
thanks a lot
Rob
Using code from this site, I've managed to create a CGI that will send a binary file to a user. My question is: after the header has been sent, can I write to the browser anymore?
My code essentially looks like this:
elsif ($q->param('download')) {
my $file = "../htdocs/HKBeta.exe";
my @stats = stat($file);
$|++; # Disable output buffering
my $nl=$/; # Save the newline character
undef $/;
open(F,$file) || die $!;
binmode(F); # Open the file in binary mode
my $file_contents=<F>; # Read the entire file into a single variable
close(F);
$/=$nl; # Restore the newline character
print header( -type => 'application/octet-stream'
-Content_Disposition => 'attachment; filename=HKBeta.exe',
-Content_Length => $stats[7],
);
print $file_contents;
print "<p>** hello. testing.....";
display_footer();
Clicking the download button causes the save-as window to popup but I can't do anything after this - should this be possible?
thanks a lot
Rob
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
i once tried combining header requests such as:
-type=>'text/html'
together with
-type=>'image/gif'
which is nearly impossible...
-type=>'text/html'
together with
-type=>'image/gif'
which is nearly impossible...
ASKER
Thanks - I'll give it a go!
goodluck! ;)
#
#
print "Content-type: text/html\n\n";
do_whatever_next();
display_footer();