473,387 Members | 3,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

zip file corrupted over HTTP

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.
Expand|Select|Wrap|Line Numbers
  1. #!/perl/bin/Perl.exe
  2.  
  3. use CGI;
  4.  
  5. use Archive::Zip qw( :ERROR_CODES );
  6.  
  7. print "Content-type: text/html \n\n";
  8.  
  9.  
  10.  
  11.  
  12. my $rme = new CGI;
  13. my $zip = Archive::Zip->new();
  14. my $file_name="";
  15. my $zipFile="";
  16.  
  17. #print "Searching file_name :: $file_name.....\n";
  18.  
  19. #To check whether the given file is available in the directory or not
  20.  
  21. opendir MYDIR, ".";
  22. @contents = readdir MYDIR;
  23.  
  24.  
  25. foreach(@contents)
  26. {
  27.  
  28. for($i = 0; $i < 140; ++$i)
  29. {
  30. #$zip->read("tst.zip") == AZ_OK or die "read error\n";
  31.  
  32.  
  33. $file_name="IOS_".$i.".xml";
  34. if($_ eq $file_name)
  35. {
  36. open(FILE1,$file_name);
  37. open(FILE,$file_name) or die "ERROR: Cannot Open file ($!)";
  38. while(<FILE>)
  39. {
  40.  
  41.  
  42. print FILE1 "$_";
  43. }
  44. $zip->addFile($file_name);
  45. unless ( $zip->writeToFileNamed('someFile.zip') == AZ_OK )
  46. {
  47. die 'write error';
  48. }
  49. print "************";
  50. last;
  51. }
  52. }
  53.  
  54. }
  55. #print ".$zip.".zip";
  56. print "<html><body>";
  57. print "<form action='/cgi-bin/filesave.pl'>";
  58. print "<select size='1' name='ID'>";
  59. print "<option value='someFile.zip'>someFile.zip</option> ";
  60. print "<option value='IOS_124.xml'>IOS_124.xml</option> ";
  61. print "</select>";
  62. print "<input type='submit' value='Submit' name='B1'>";
  63. print "</form></body></html>";
  64.  
To download the zip file
Expand|Select|Wrap|Line Numbers
  1. #!/perl/bin/Perl.exe
  2. #print "Content-type: text/html\n\n";
  3. use CGI ':standard';
  4. use CGI::Carp qw(fatalsToBrowser);
  5.  
  6. my $files_location;
  7. my $ID;
  8. my @fileholder;
  9. print "hello";
  10. #$files_location = "/cgi";
  11.  
  12. $ID = param('ID');
  13.  
  14. if ($ID eq '') {
  15.  
  16. print "You must specify a file to download.";
  17. } else {
  18.  
  19. open(DLFILE, "<$ID") || Error('open', 'file');
  20. @fileholder = <DLFILE>;
  21. close (DLFILE) || Error ('close', 'file');
  22.  
  23.  
  24.  
  25. print "Content-Type:application/x-octet-stream\n";
  26. print "Content-Disposition:attachment;filename=$ID\n\n";
  27. print "Content-Length;length <DLFILE>";
  28. print @fileholder
  29. }
Can anybody help me on this?
Mar 28 '08 #1
4 3419
KevinADC
4,059 Expert 2GB
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');

Expand|Select|Wrap|Line Numbers
  1. print "Content-Type:application/x-download\n";
  2. print "Content-Length: $size\n";
  3. print "Content-Disposition:attachment;filename=$ID\n\n";
  4. print @fileholder
  5. }
Mar 28 '08 #2
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.
Mar 28 '08 #3
Hi,

Will this same script work in solaris plat form or we need to do some changes?
Apr 4 '08 #4
KevinADC
4,059 Expert 2GB
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.
Apr 4 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
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...
48
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...
7
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...
3
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)...
1
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. ...
13
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...
1
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() ....
3
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...
4
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...
16
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...
0
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,...
0
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...
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
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,...
0
Oralloy
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.