<?php

// $exdir is the directory you want the content of the compressed file to be extracted
// use for the value of exdir unix style
// if overwrite is 1 old files with same names will be replaced, if 0 old files will be spared :P

class extract
{

// used to extract zip files
// if password is filled in the zip file will be encrypted
function extract_zip($file,$overwrite=0,$exdir="",$password=""){
	
	//building the command	
	$para['password']  = (!empty($password)) ? "-P ".$password." " : "";
	$para['overwrite'] = ($overwrite == 1) ? " -o " : " -n ";
	$para['exdir']     = (!empty($exdir)) ? "-d ".$exdir." " : "";
	exec("unzip".$para['overwrite'].$para['password']." ".$file." ".$para['exdir']);
	
}


// used to extract gz files 
function extract_gz($file,$overwrite=0,$exdir=""){
	
	//building the command
	$para['overwrite'] = ($overwrite == 1) ? "" : " -k";
	$para['exdir']     = (!empty($exdir)) ? "-C ".$exdir." " : "";
	echo exec("tar -zxf ".$file." ".$para['exdir'].$para['overwrite']);
	
}


// used to extract bz2 files 
function extract_bz2($file,$overwrite=0,$exdir=""){
	
	//building the command
	$para['overwrite'] = ($overwrite == 1) ? "" : " -k";
	$para['exdir']     = (!empty($exdir)) ? "-C ".$exdir." " : "";
	exec("tar -jxf ".$file." ".$para['exdir'].$para['overwrite']);	
	
}

// end of class
// in the future i will build a check that will verify the extracted files.
}

// example
$test = new extract();
$test->extract_gz("test.tar.gz",1"./output");

// another example
extract::extract_gz("test.tar.gz",1"./output");
?> 
