in reply to Re^3: CRC Error on ZIP Files
in thread CRC Error on ZIP Files

Hi Hazylife !

sorry for answering late ! Yes, sure, below you find the complete script.
It gets called with two parameters, the path and the name of the file to be downloaded

I left all the commented sections inside, they result from different approaches
to the function or they were meant to provide information
of what the script was receiving and doing with it.

Having downloaded the file, the source directory gets removed.
Finally the script calls a defined URL to return to

Thanks for your efforts !

Cheers
Uli

#!/usr/bin/perl #use warnings; # open (datei, "<liste.txt"); # $verzeichnis=<datei>; # close datei; $Datten = $ENV{'QUERY_STRING'}; @Daten=split(/&/, $Datten); @dateien=split(/=/, @Daten[0]); @verz=split(/=/, @Daten[1]); $verzeichnis = @verz[1]; # print "Content-type: text/html\n\n"; # # print $Datten."<br>\n"; # print @Daten."<br>\n"; # print @dateien."<br>\n"; # print @verz."<br>\n"; # print $verzeichnis."<br>\n"; # print @dateien[1]."<br>\n"; # exit; download($verzeichnis, @dateien[1]); # $url = $verzeichnis.@dateien[1]; # print "Location: $url\n\n"; wait(); use File::Path qw( rmtree ); rmtree( $verzeichnis ); # Verzeichnisse in downloads, ‰lter as 1 Tag lˆschen # opendir(zeig,'../downloads/./'); # @entries = readdir(zeig); # close zeig; opendir zeig, '../downloads/./'; while ($entry = readdir zeig){ push (@entries, $entry); } #$index=-1; open (file, ">", "aktion.txt"); print file @entries; foreach $entry (@entries) { #$index++; print file $entry."\n"; if ($entry ne '.' && $entry ne '..' && $entry ne "index.html") { if(-d "../downloads/$entry") { if ((-M "../downloads/$entry") >1 ) { rmtree( "../downloads/$entry" ); print file " wurde gelöscht\n"; } } } } close (file); open (datei,">","fertig.txt"); print datei "Nachhause.pl !"; close datei; # $status=""; # $status=system("../cgi-bin/nachhause.pl","../donwloads/index.html"); # # wiederwarten: # unless ($status ne "") { # goto wiederwarten; # } heimat(); exit; sub download { use CGI; $html=new CGI; #print $html->header(-type => 'application/octet-stream', -attachment +=> $_[1]); print $html->header(-type => 'application/zip', -attachment => $_[1]); + open($peunter, "<", $_[0].$_[1]); binmode($peunter); binmode STDOUT; while (read($peunter,$bytes,1024)) { unless (eof()) { #unless (length($bytes)<1024) { chomp($bytes); } print $bytes; } #@data = <$peunter>; close($peunter); #print "@data"; } sub heimat { # use CGI; # # $htm=new CGI; # print $htm->header(-type =>'text/html', -expires => 'now'); # print $htm->system("../cgi-bin/nachhause.pl","../donwloads/index.htm +l"); $- =0; system("../cgi-bin/nachhause.pl","../donwloads/index.html"); }

Replies are listed 'Best First'.
Re^5: CRC Error on ZIP Files
by hazylife (Monk) on Mar 11, 2014 at 21:14 UTC
    What happens if you comment out unless (eof()) { chomp($bytes) } and the call to heimat()?
      Hi Hazylife,
      I checked according to your suggestion. Results are :
      whether "heimat" is getting called or not, doesn't make a difference.

      when commenting out the eof check everything is running fine, as long as the
      amount of data downloaded does not exceed the buffer's size, regardless whether
      there are one to two files. The very moment the data is more than
      the buffers size (again no matter whether due to the size of one file or due to
      the number of files) I end up with a corrupted file amoung the files transported
      The last file transported ( a jpeg) is showing only half of the original
      Any clues ?

        whether due to the size of one file or due to the number of files
        "the number of files" - as in "the number of files within the archive", right? Because download() only handles one file at a time.
        Any clues ?
        Come to think of it, this could be a server configuration issue (google "mod_gzip" OR "mod_deflate" zip corruption). What happens if you put a (preferably large) ZIP archive somewhere within the document root and download it using the direct link?

        Well, anyway, try this slightly modified version of download:

        sub download { my $filename = $_[0].$_[1]; use CGI; $html=new CGI; $| = 1; print $html->header( -type => 'application/zip', -charset => 'binary', -attachment => $_[1], -Content_length => -s $filename); open($peunter, "<", $filename); binmode($peunter); binmode STDOUT; while (read($peunter,$bytes,1024)) { print $bytes; } close($peunter); }