PHP gunzip, unzip File Extractor

By Hawkee on Jun 21, 2007

This will extract a zip file via PHP. Just be sure to set the $file and $path variables. $file represents the zip file name which may or may not contain a path. $path represents the directory to extract the files to. It will determine if the file is gz or zip and act accordingly. This uses the command line so be aware of the security risk.

Be very careful to double check $file if you take it from $_GET or $_POST

This can be used in conjunction with my Wget FTP CSV Datafeed Import Script

$path = '/extracted';
$file = 'zipfile.gz';

$path_parts = pathinfo($file);
$ext = $path_parts[extension];

if($ext == 'gz')
    $execute = "gunzip -".$path." $file";
if($ext == 'zip')
    $execute = "unzip -u $file -d $path";


Sign in to comment.
Hawkee   -  Aug 10, 2007

Snipe, no need if you\'re only going to use it in a command line script. I don\'t use this through a web interface.

Snipe   -  Aug 10, 2007

You should make it, so theres like a input box, and you type the name of the file, and click Extract, and it does it that way. If you don\'t I might make it later, but great job man!

Hawkee   -  Jul 07, 2007

It\'s built for a *nix server, yes.

Blank   -  Jul 07, 2007

Is this script a *nix only script?

Hawkee   -  Jun 26, 2007

edynas, I don\'t think you can issue unzip commands via FTP. Definitely best to do it via ssh.

edynas   -  Jun 26, 2007

Wondering if it work in combination with ftp. So if I make connection to an other server I have rights to ftp the zip to it and extract it there using the remote path and file name?

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.