I have perl script which will make a zip file and create a HTML form with asubmit button to send the zip file client. When user click the download button the zip file will be downloaded. But the problem is now the downloaded zip file is corrupted.
here the scripts i wrote.
To create the Zip file.
[CODE=perl]#!/perl/bin/Perl.exe
use CGI;
use Archive::Zip qw( :ERROR_CODES );
print "Content-type: text/html \n\n";
my $rme = new CGI;
my $zip = Archive::Zip->new();
my $file_name="";
my $zipFile="";
#print "Searching file_name :: $file_name..... \n";
#To check whether the given file is available in the directory or not
opendir MYDIR, ".";
@contents = readdir MYDIR;
foreach(@conten ts)
{
for($i = 0; $i < 140; ++$i)
{
#$zip->read("tst.zip" ) == AZ_OK or die "read error\n";
$file_name="IOS _".$i.".xml" ;
if($_ eq $file_name)
{
open(FILE1,$fil e_name);
open(FILE,$file _name) or die "ERROR: Cannot Open file ($!)";
while(<FILE>)
{
print FILE1 "$_";
}
$zip->addFile($file_ name);
unless ( $zip->writeToFileNam ed('someFile.zi p') == AZ_OK )
{
die 'write error';
}
print "********** **";
last;
}
}
}
#print ".$zip.".zi p";
print "<html><bod y>";
print "<form action='/cgi-bin/filesave.pl'>";
print "<select size='1' name='ID'>";
print "<option value='someFile .zip'>someFile. zip</option> ";
print "<option value='IOS_124. xml'>IOS_124.xm l</option> ";
print "</select>";
print "<input type='submit' value='Submit' name='B1'>";
print "</form></body></html>";
[/CODE]
To download the zip file
[CODE=perl]#!/perl/bin/Perl.exe
#print "Content-type: text/html\n\n";
use CGI ':standard';
use CGI::Carp qw(fatalsToBrow ser);
my $files_location ;
my $ID;
my @fileholder;
print "hello";
#$files_locatio n = "/cgi";
$ID = param('ID');
if ($ID eq '') {
print "You must specify a file to download.";
} else {
open(DLFILE, "<$ID") || Error('open', 'file');
@fileholder = <DLFILE>;
close (DLFILE) || Error ('close', 'file');
print "Content-Type:applicatio n/x-octet-stream\n";
print "Content-Disposition:att achment;filenam e=$ID\n\n";
print "Content-Length;length <DLFILE>";
print @fileholder
}[/CODE]
Can anybody help me on this?
here the scripts i wrote.
To create the Zip file.
[CODE=perl]#!/perl/bin/Perl.exe
use CGI;
use Archive::Zip qw( :ERROR_CODES );
print "Content-type: text/html \n\n";
my $rme = new CGI;
my $zip = Archive::Zip->new();
my $file_name="";
my $zipFile="";
#print "Searching file_name :: $file_name..... \n";
#To check whether the given file is available in the directory or not
opendir MYDIR, ".";
@contents = readdir MYDIR;
foreach(@conten ts)
{
for($i = 0; $i < 140; ++$i)
{
#$zip->read("tst.zip" ) == AZ_OK or die "read error\n";
$file_name="IOS _".$i.".xml" ;
if($_ eq $file_name)
{
open(FILE1,$fil e_name);
open(FILE,$file _name) or die "ERROR: Cannot Open file ($!)";
while(<FILE>)
{
print FILE1 "$_";
}
$zip->addFile($file_ name);
unless ( $zip->writeToFileNam ed('someFile.zi p') == AZ_OK )
{
die 'write error';
}
print "********** **";
last;
}
}
}
#print ".$zip.".zi p";
print "<html><bod y>";
print "<form action='/cgi-bin/filesave.pl'>";
print "<select size='1' name='ID'>";
print "<option value='someFile .zip'>someFile. zip</option> ";
print "<option value='IOS_124. xml'>IOS_124.xm l</option> ";
print "</select>";
print "<input type='submit' value='Submit' name='B1'>";
print "</form></body></html>";
[/CODE]
To download the zip file
[CODE=perl]#!/perl/bin/Perl.exe
#print "Content-type: text/html\n\n";
use CGI ':standard';
use CGI::Carp qw(fatalsToBrow ser);
my $files_location ;
my $ID;
my @fileholder;
print "hello";
#$files_locatio n = "/cgi";
$ID = param('ID');
if ($ID eq '') {
print "You must specify a file to download.";
} else {
open(DLFILE, "<$ID") || Error('open', 'file');
@fileholder = <DLFILE>;
close (DLFILE) || Error ('close', 'file');
print "Content-Type:applicatio n/x-octet-stream\n";
print "Content-Disposition:att achment;filenam e=$ID\n\n";
print "Content-Length;length <DLFILE>";
print @fileholder
}[/CODE]
Can anybody help me on this?
Comment