473,662 Members | 2,581 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

zip file corrupted over HTTP

7 New Member
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 3445
KevinADC
4,059 Recognized Expert Specialist
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(@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>";

To download the zip file
#!/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
}
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
nitupatra
7 New Member
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:att achment;filenam e=$ID\n\n";
print @fileholder
}
Hi

Its working fine now .Thanks for your help.
Mar 28 '08 #3
nitupatra
7 New Member
Hi,

Will this same script work in solaris plat form or we need to do some changes?
Apr 4 '08 #4
KevinADC
4,059 Recognized Expert Specialist
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
6113
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 downloads. It uses fpassthru() and some headers() to send a file to the requesting user. The get.php file that I wrote (the file download module if you will) works like a charm for .ZIP files and .TXT files. However, when .EXE files are downloaded...
48
8470
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 problem. The program may crash unexpectedly while writing to the file. If so, my program should detect this during startup, and then (during startup) probably delete the data added to the file and redo the writing operation.
7
2324
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 maybe it will save time for someone else who runs into this problem... ================================================ Environment: - Microsoft Windows 2000 Pro
3
5820
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) documents successfully. Is there anything we have to take care of, while handling uploads of excel documents with macros? Thanks in advance,
1
6664
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. Some of the data are still missing because the tables we want still has sone 'chain mis linkage' error when we did a DBCC checkdb/checktable. DBCC couldn't fix those errors either. We're pretty sure that there are some data still burry under the...
13
9509
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 Dir(strLDB) <> "" Then Kill (strLDB) where strLDB is the path to the ldb file. The client advises that the ldb doesn't lurk after the program closes. Any ideas?
1
3124
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
10503
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 Explorer and delete the file to get things working again, but I'd rather just catch the exception and resolve the error programatically. I tried "Properties.Settings.Default.Reset();" but that just throws the exception too. Does anyone know how I can...
4
4243
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 this issue when i store and retrieve files of type .doc i am storing the file in a column of datatype image. Here is the code where i insert the file into database. Am sure the code is working. its just not working for .docx protected void...
16
4236
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 table via relationships. Each user has their own copy of the frontend which links back to the data file on the server. The corrupted data file repairs OK but on both occasions 2 relationships have disappeared in the Relationships Window. When...
0
8344
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8857
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8764
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5654
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.