PDA

View Full Version : zip or gzip extraction


Tomek
08-24-2006, 04:01 AM
hi
on my page, i have a csv file which has to be updated frequently.
i have added a cron job which automaticly runs a php script which downloads the new file from given adress.
the problem is that this file is in zip format. (.gz format also available)
now... to unzip this file, i think i have to use perl which i know very little about.
i've searched the internet, but i just couldn't find a script that would work properly
can anyone help please?

thx in advance
Tomek

FishMonger
08-24-2006, 05:02 AM
use Archive::Tar
http://search.cpan.org/~kane/Archive-Tar-1.30/lib/Archive/Tar.pm

or

use Compress::Zlib
http://search.cpan.org/~pmqs/Compress-Zlib-1.42/Zlib.pm

Tomek
08-24-2006, 01:44 PM
thx, but you have to know i'm a noob, so where do i specify which file to extract?

threetimechamps
09-04-2006, 09:51 AM
out of curriosity what does your cron script look like?

rwedge
09-10-2006, 07:45 AM
This is an expample to try on a linux or unix host using perl and shell:#!/usr/bin/perl -w
use strict;
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
my ($fname, $bro, $res, $rlt);
## URL to the compressed remote file - zip or qz
my $url = 'http://www.remotehost.com/cvs_file.zip';
($fname=$url) =~ s/.*[\/\\](.*)$/$1/;
print "Content-type: text/plain\n\n";
use LWP::UserAgent;
$bro = LWP::UserAgent->new();
$res = $bro->mirror($url, $fname);
if ($res->is_success) {
$rlt = ($fname =~ /\.zip$/i)? `unzip $fname`: `gzip -l $fname; gzip -d $fname`;
print "$rlt";
unlink($fname);
}
else {
print $res->status_line;
}