CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Archive::Zip Usage

 



Mordred
Novice

Oct 7, 2002, 2:51 PM

Post #1 of 8 (1072 views)
Archive::Zip Usage Can't Post

Hi, I'm wondering of anyone can give me some pointers on the usage of Archive::Zip. I've looked at the examples and docs, but not one aspect of it will work for me. I must be doing something wrong. I am trying to extract a text file from a zip file, retrieve the contents of the text file, then use that text in the script. At the moment I'm using code as follows:



$url =
"$FORM{'fileurl'}/$filename";
$filepath =
"$FORM{'filepath'}/$filename";

if
("$ext" eq "zip") {
my $dirName =
'extractTest';
use Archive::Zip;
my $zip = Archive::Zip->new();
my $status = $zip->read( $filepath );
if (
"$status" eq "AZ_OK") {
my $status = $zip->extractMemberWithoutPaths( $cfdescfile );
if (
"$status" eq "AZ_OK") {
$cfdescpath =
"$FORM{'filepath'}/$cfdescfile";
$fsize = (-s $cfdescpath);
open(IN,
"$cfdescpath");
read(IN,$buf,$fsize);
close(IN);
}
}
}


This recognizes the file as a zip but fails to do anything to it. It outputs no error messages. I find the docs for this package woefully inadequate. It looks like I'm basically gonna hafta just play with syntax after syntax till I stumble upon the right combo. Does anyone know of an easier way to do this?


thebitch
User

Oct 8, 2002, 1:03 AM

Post #2 of 8 (1063 views)
Re: [Mordred] Archive::Zip Usage [In reply to] Can't Post

Where did you get

Code
("$status" eq "AZ_OK")

from?

Did you know that AZ_OK is a subroutine ?
You should read the documentation again,
and pay close attention to detail
( "eq" is never used anywhere )


Quote
ERROR CODES

Many of the methods in Archive::Zip return error codes. These are implemented as inline subroutines, using the use constant pragma. They can be imported into your namespace using the :CONSTANT tag:

use Archive::Zip qw( :CONSTANTS );
...
die "whoops!" if $zip->read( 'myfile.zip' ) != AZ_OK;
AZ_OK (0)

Everything is fine.

AZ_STREAM_END (1)

The read stream (or central directory) ended normally.

AZ_ERROR (2)

There was some generic kind of error.

AZ_FORMAT_ERROR (3)

There is a format error in a ZIP file being read.

AZ_IO_ERROR (4)

There was an IO error.



davorg
Thaumaturge / Moderator

Oct 8, 2002, 1:07 AM

Post #3 of 8 (1064 views)
Re: [Mordred] Archive::Zip Usage [In reply to] Can't Post

I haven't used Archive::Zip but I notice that the author has written a FAQ which may be of use to you.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


Mordred
Novice

Oct 8, 2002, 2:54 AM

Post #4 of 8 (1060 views)
Re: [thebitch] Archive::Zip Usage [In reply to] Can't Post

Gee what a wonderfully informative post. Did you know I had trouble following the documentation? Maybe you should read my post more carefully and pay close attention to detail. Then you might recognise that simply copy pasting a section from the docs does not help in the least. Obviously I'm using AZ_OK wrongly. Instead of throwing attitude around about how I should just read the manual, you should actually try to make a contructive and helpful comment. If you don't have anything contructive to post, don't post at all.


Paul
Enthusiast

Oct 8, 2002, 3:17 AM

Post #5 of 8 (1056 views)
Re: [Mordred] Archive::Zip Usage [In reply to] Can't Post

Don't worry about it, thebitch has a hardon for himself.

One thing I notice is the way you are assigning your paths.


Code
$url = "$FORM{'fileurl'}/$filename";  
$filepath = "$FORM{'filepath'}/$filename";


This is very insecure as the url and path both look like user input but they aren't checked for validity which is a big security risk.

Check this out:

http://search.cpan.org/author/NEDKONZ/Archive-Zip-1.05/lib/Archive/Zip/FAQ.pod#Sample_code_


Mordred
Novice

Oct 8, 2002, 3:23 AM

Post #6 of 8 (1055 views)
Re: [Mordred] Archive::Zip Usage [In reply to] Can't Post

Just thought I'd add that the message above is to thebitch. I recognise you've probably spotted the problem in AZ_OK however unlike some, I do read and research a topic before I submit myself to the probable scorn and patronising attitude that's all too prevalent on programming forums. You can consider that a post from me means I'm stumped after reading all I could get my hands on. Therefore I consider the notion that all I need to do is just read the doc again to be disrespectful and unhelpful. Maybe you don't give a shit, but respect is a two way street. You get as good as you give.

Davorg, I had checked cpan. It's where I got the module originally. I downloaded the source and read his examples and docs as well. I cobbled the above code from his examples. Thanks for the link though.


Mordred
Novice

Oct 8, 2002, 3:34 AM

Post #7 of 8 (1051 views)
Re: [RedRum] Archive::Zip Usage [In reply to] Can't Post

Hi Redrum, yeah they're not being checked atm. The form variables are being passed from the admin panel of a script I'm just beginning. I'm a bit slack sometimes when I first write things and also not being so strict on input lets me play around. The script is just for me, and protected by a htaccess password and a stored blowfish encrypted password as well which I guess encourages my slackness. I'll add checking before the script goes into mainstream use :)


thebitch
User

Oct 8, 2002, 3:38 AM

Post #8 of 8 (1051 views)
Re: [Mordred] Archive::Zip Usage [In reply to] Can't Post

so I didn't help at all? ( did you figure it out)


Code
die "whoops!" if $zip->read( 'myfile.zip' ) != AZ_OK;


AZ_OK is a subroutine.
"AZ_OK" is a string.
eq is the equality operator for strings.
== is the equiality operator for numbers
you need to use

Code
if ($status == AZ_OK ) {  ...

I don't particularly care for people cussing at me, talk about respect.
I am not being disrespectful.
When I start calling you a names and cussing at you, that is when I am being disrespectfull.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives