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";
    `$execute`;
}
if($ext == 'zip')
{
    $execute = "unzip -u $file -d $path";
    `$execute`;
}

Comments

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.

 Respond  
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!

 Respond  
Hawkee   -  Jul 07, 2007

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

 Respond  
Blank   -  Jul 07, 2007

Is this script a *nix only script?

 Respond  
Hawkee   -  Jun 26, 2007

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

 Respond  
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?

 Respond  
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.