get a zipfile with a perl script

  • sliva
  • Born
  • Born
  • sliva
  • Posts: 3

Post 3+ Months Ago

I´m having trouble with a simple perl script, anyone can tell me what I´m doing wrong?

I get this messsage on WinZip when I try to open the file.

Error in file #1: bad Zip file offset (Error local header signature not found): 0
(attempting to re-compensate)
Extracting darla.jpg
Error: unexpected end of file encountered
Error: invalid compressed data to inflate



#!/usr/local/bin/perl

chdir ("d:\\www\\mypage.net\\www\\test\\");

$zipfile = "zipfile.zip";

print "Content-type:application/x-zip-compressed\n\n";

open FILE, "< $zipfile";

binmode FILE;

print <FILE>;

close FILE;
  • phpSelectah
  • Student
  • Student
  • User avatar
  • Posts: 97

Post 3+ Months Ago

As far as I can tell .. the line :

Code: [ Select ]
print "Content-type:application/x-zip-compressed\n\n";


should be :
Code: [ Select ]
print "Content-type:application/x-zip-compressed\r\n\r\n";


as \n\n is not valid HTTP 1.0.

Also, double check to make sure the archive is not corrupted.

These are the only things I noticed with the info given.

Hth
:D
  • sliva
  • Born
  • Born
  • sliva
  • Posts: 3

Post 3+ Months Ago

Unfortunately is not this, but tks in advance.
  • phpSelectah
  • Student
  • Student
  • User avatar
  • Posts: 97

Post 3+ Months Ago

Usually, when I am dumping a file directly to a browser I use:

Code: [ Select ]

    my $zipfile = "bla.zip";
       open (ZIP,"$zipfile") || die();
       binmode ZIP;
       $/=undef;
    my $data = <ZIP>;

 print "Content-type:application/x-zip-compressed\r\n\r\n";
 print $data;
  1.     my $zipfile = "bla.zip";
  2.        open (ZIP,"$zipfile") || die();
  3.        binmode ZIP;
  4.        $/=undef;
  5.     my $data = <ZIP>;
  6.  print "Content-type:application/x-zip-compressed\r\n\r\n";
  7.  print $data;



I am curious as to why this doesn't work ;(
  • sliva
  • Born
  • Born
  • sliva
  • Posts: 3

Post 3+ Months Ago

Anyway I did it in ASP, but if u find a solution tell me.



<%

Response.Buffer = True
Response.Clear
Response.AddHeader "content-disposition", "attachment; filename=zipfile.zip"
Response.ContentType = "application/x-zip-compressed"

Const adTypeBinary = 1
Dim strFilePath

strFilePath = "d:\\www\\mypage.net\\www\\zipfile.zip"

Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath

Response.BinaryWrite objStream.Read

objStream.Close
Set objStream = Nothing
%>

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 45 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.