relax99 has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I was wondering if anyone knew of the best way to output a refreshed page from a cgi program and then start a file download to the user's computer.
Basically, I have a Perl cgi program that creates new excel files on the fly, based on the information submitted in the form. The form contains a browser file upload field to let the user submit the data. What I want to do is first refresh the webpage to provide additional information to the user after they submit the form and then start the download.
I looked around, but the only two things I could find that were similar to what I am doing were:
1. When the user submits the form, insert form submit code into the form's onLoad() event, so that when the webpage refreshes it would submit itself again, this time indicating to the cgi program that it should start the required download.
Problems with this approach:
# create excel file my ($fh, $xls_filename) = tempfile(DIR => $tempfile_path, SUFFIX => ". +xls", UNLINK => 1); my $xls_workbook = Spreadsheet::WriteExcel->new($xls_filename); my $xls_worksheet = $xls_workbook->add_worksheet(); ### inserting data into the worksheet $xls_workbook->close(); my $download_filename = "standard_filename.xls"; print "Content-Title: $download_filename\n"; print "Content-Disposition: attachment; filename=$download_filename\n" +; print "Content-Type: application/octet-stream; file=$download_filename +\n\n"; open(XLS, $xls_filename) or die "can't open temporary excel file: $!\n +"; binmode XLS; binmode STDOUT; my $buff; while( read(XLS, $buff, 1024) ) { print STDOUT $buff; } close(XLS); exit(0); # exit for now - without refreshing the screen
Any insights, anyone?
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Refresh page then download from a cgi program
by sgifford (Prior) on Aug 09, 2004 at 20:24 UTC | |
|
Re: Refresh page then download from a cgi program
by roju (Friar) on Aug 09, 2004 at 20:17 UTC |