Top

PHP gunzip, unzip File Extractor


PHP Code
+ 0 likes
Please Register to submit score.
Bookmark and Share
Average Score  9.0 (of 1 scores)
Date Added  Jun 21, 2007
Last Updated  Jun 21, 2007
Tags  file  gunzip  unzip 

Introduction

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

Grab the Code

$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

  (6)  RSS
edynas
Comments: 1
 
PHP Snippet:  PHP gunzip, unzip File Extractor
Posted on Jun 26, 2007 1:07 pm
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?
Hawkee
Comments: 1,039
 
PHP Snippet:  PHP gunzip, unzip File Extractor
Posted on Jun 26, 2007 5:10 pm
edynas, I don't think you can issue unzip commands via FTP. Definitely best to do it via ssh.
Blank
Comments: 6
 
PHP Snippet:  PHP gunzip, unzip File Extractor
Posted on Jul 7, 2007 4:48 am
Is this script a *nix only script?
Hawkee
Comments: 1,039
 
PHP Snippet:  PHP gunzip, unzip File Extractor
Posted on Jul 7, 2007 1:31 pm
It's built for a *nix server, yes.
Snipe
Comments: 7
 
PHP Snippet:  PHP gunzip, unzip File Extractor
Posted on Aug 10, 2007 3:33 pm
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
Comments: 1,039
 
PHP Snippet:  PHP gunzip, unzip File Extractor
Posted on Aug 10, 2007 6:44 pm
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.

Commenting Options

Register or Login to Hawkee.com or use your Facebook or Twitter account by clicking the corresponding button below.

  
Bottom