zip file corrupted over HTTP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nitupatra
    New Member
    • Mar 2008
    • 7

    #1

    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.
    [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?
    Last edited by eWish; Mar 28 '08, 01:42 PM. Reason: Please use code tags
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    Originally posted by nitupatra
    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');

    Code:
    print "Content-Type:[B]application/x-download[/B]\n";
    print "Content-Length: [B]$size[/B]\n";
    print "Content-Disposition:attachment;filename=$ID\n\n";
    print @fileholder
    }

    Comment

    • nitupatra
      New Member
      • Mar 2008
      • 7

      #3
      Originally posted by KevinADC
      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.

      Comment

      • nitupatra
        New Member
        • Mar 2008
        • 7

        #4
        Hi,

        Will this same script work in solaris plat form or we need to do some changes?

        Comment

        • KevinADC
          Recognized Expert Specialist
          • Jan 2007
          • 4092

          #5
          Originally posted by nitupatra
          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.

          Comment

          Working...