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. - #!/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(@contents)
-
{
-
-
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,$file_name);
-
open(FILE,$file_name) or die "ERROR: Cannot Open file ($!)";
-
while(<FILE>)
-
{
-
-
-
print FILE1 "$_";
-
}
-
$zip->addFile($file_name);
-
unless ( $zip->writeToFileNamed('someFile.zip') == AZ_OK )
-
{
-
die 'write error';
-
}
-
print "************";
-
last;
-
}
-
}
-
-
}
-
#print ".$zip.".zip";
-
print "<html><body>";
-
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.xml</option> ";
-
print "</select>";
-
print "<input type='submit' value='Submit' name='B1'>";
-
print "</form></body></html>";
-
To download the zip file - #!/perl/bin/Perl.exe
-
#print "Content-type: text/html\n\n";
-
use CGI ':standard';
-
use CGI::Carp qw(fatalsToBrowser);
-
-
my $files_location;
-
my $ID;
-
my @fileholder;
-
print "hello";
-
#$files_location = "/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:application/x-octet-stream\n";
-
print "Content-Disposition:attachment;filename=$ID\n\n";
-
print "Content-Length;length <DLFILE>";
-
print @fileholder
-
}
Can anybody help me on this?
4 3419
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.
#!/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(@contents)
{
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,$file_name);
open(FILE,$file_name) or die "ERROR: Cannot Open file ($!)";
while(<FILE>)
{
print FILE1 "$_";
}
$zip->addFile($file_name);
unless ( $zip->writeToFileNamed('someFile.zip') == AZ_OK )
{
die 'write error';
}
print "************";
last;
}
}
}
#print ".$zip.".zip";
print "<html><body>";
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.xml</option> ";
print "</select>";
print "<input type='submit' value='Submit' name='B1'>";
print "</form></body></html>";
To download the zip file
#!/perl/bin/Perl.exe
#print "Content-type: text/html\n\n";
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);
my $files_location;
my $ID;
my @fileholder;
print "hello";
#$files_location = "/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:application/x-octet-stream\n";
print "Content-Disposition:attachment;filename=$ID\n\n";
print "Content-Length;length <DLFILE>";
print @fileholder
}
Can anybody help me on this?
See if this helps:
[code] $size = -s $ID;
open(DLFILE, "<$ID") || Error('open', 'file'); binmode DLFILE;
@fileholder = <DLFILE>;
close (DLFILE) || Error ('close', 'file'); -
print "Content-Type:application/x-download\n";
-
print "Content-Length: $size\n";
-
print "Content-Disposition:attachment;filename=$ID\n\n";
-
print @fileholder
-
}
See if this helps: $size = -s $ID;
open(DLFILE, "<$ID") || Error('open', 'file'); binmode DLFILE;
@fileholder = <DLFILE>;
close (DLFILE) || Error ('close', 'file');
print "Content-Type:application/x-download\n";
print "Content-Length: $size\n";
print "Content-Disposition:attachment;filename=$ID\n\n";
print @fileholder
}
Hi
Its working fine now .Thanks for your help.
Hi,
Will this same script work in solaris plat form or we need to do some changes?
Hi,
Will this same script work in solaris plat form or we need to do some changes?
If it does not work I guess you may need to make some changes, but I wouldn't know what changes.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Brandon Walters |
last post by:
I wrote a file download module for my website. The reason for the file
download module is that my website downloads work on a credit based system.
So I need to keep track of and limit daily...
|
by: Joseph |
last post by:
Hi
I'm writing a commercial program which must be reliable. It has to do
some basic reading and writing to and from files on the hard disk,
and also to a floppy.
I have foreseen a potential...
|
by: Stuart McGraw |
last post by:
I just spent a $*#@!*&^&% hour registering at ^$#@#%^
Sourceforce and trying to submit a Python bug report
but it still won't let me. I give up. Maybe someone who
cares will see this post, or...
|
by: Prakash |
last post by:
Hi,
We face problems uploading excel (with macros) documents using HTML
File Upload.
The file contents are corrupted while viewing the same. However, we
are able to upload excel (w/o. macros)...
|
by: WKC |
last post by:
Recently, one of our database's mdf and ldf was corrupted. We were able to
bring back the database with the capability of importing and querying the
data. However, the data is not the full list. ...
|
by: Bob Darlington |
last post by:
I have a repair and backup database routine which runs when a user closes
down my application.
It works fine in my development machine, but breaks on a client's at the
following line:
If...
|
by: Atara |
last post by:
My application starts with:
Module mmcMain
Public Sub Main()
Debug.WriteLine("Main begin")
Dim splashForm As New mcDlgs.cmcDlgSplash2
splashForm.Show()
....
|
by: Jeremy Chaney |
last post by:
It appears that my user.config file got corrupted causing my
"InitializeComponent" routine to throw the exception "Root element is
missing." when I start my app.
I figure I can just go into...
|
by: =?Utf-8?B?U1VOTlk=?= |
last post by:
Hi, i am uploading a .docx file into sql2005 and later when i retrieve the
file from the database and i open it, i get a error message "The file is
corrupted and cannot be open". I am not facing...
|
by: Wayne |
last post by:
I have an Access 2003 data file that has now corrupted twice in a
week. The database is extremely simple with one main data table and a
few lookup tables. The lookup tables are linked to the main...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |