in reply to Archive::Zip with cgi empty zip file
For the redirection part, it's a poor idea to try and call the same module using both method and function calling. One or the other really needs to be chosen.
Option 1: Make it all function calls by importing redirect, as well.
#!/usr/bin/perl -w #use strict; use Archive::Zip qw(:ERROR_CODES :CONSTANTS); use CGI qw(:standard :nph redirect); my $id; if ($id = param('link')){ my $obj = Archive::Zip->new(); my $file_member = $obj->addFile( $id ); if ($obj->writeToFileNamed('download.zip') != AZ_OK) { print header(type => 'text/plain'); print "Bad something or other!"; } else { print redirect('http://domain.com/files/download.zip'); } }
Option 2: Make it all method calls, by not importing any functions.
#!/usr/bin/perl -w #use strict; use Archive::Zip qw(:ERROR_CODES :CONSTANTS); use CGI qw(:nph); my $q = CGI->new(); my $id; if ($id = $q->param('link')){ my $obj = Archive::Zip->new(); my $file_member = $obj->addFile( $id ); if ($obj->writeToFileNamed('download.zip') != AZ_OK) { print $q->header(type => 'text/plain'); print "Bad something or other!"; } else { print $q->redirect('http://domain.com/files/download.zip'); } }
I've also done three other things:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Archive::Zip with cgi empty zip file
by wapped (Initiate) on Mar 30, 2009 at 05:26 UTC |