PHP Code
// Purpose
//	Used to uncompress data using the PK zip format.
//	Supports password-protected data as well.
// Parameters
//	Data (String) = The data we want to uncompress.
//	Password (Optional String) = The password to use to protect the file.
//		If this is not passed, no password is passed to the unzip command.
//		If a password is passed but the data doesn't require one, the data is unzipped without errors.
//			This is the behavior of the funzip (v 3.93) command at the time of this writing.
// Return (Associative Array)
//	Array Structure
//		[StatusCode] (Number) = A code indicating the return status of the function.
//		[StatusMsg] (String) = A message related to the specified code (above).
//		[Data] (String) = The actual data returned by the function.
//	If no errors occured:
//		StatusCode = 0
//		StatusMsg = ''
//		Data = Returns the uncompressed contents of the specified file.
//	If the funzip function did not start properly (it was never considered a resource by PHP):
//		StatusCode = 1
//		StatusMsg = ''
//		Data = Returns a zero-length string.
//	If the unzip command generated error information (via STDERR):
//		StatusCode = 2
//		StatusMsg = Whatever the funzip command sent to STDERR
//		Data = Returns whatever the funzip command returned (via STDOUT).
// Version History
//	1.0 4/21/2004 Tested by Russ Tanner
//		This was tested with funzip version 3.93 (UNIX).
//---
function UnZip($Data, $Password = '') {

// Initiate variables
$sERR = ''; // Error message buffer (taken from STDERR)
$sOUT = ''; // Return buffer (taken from STDOUT)
// Return buffer
$R['StatusCode'] = 0; // Assume no error
$R['StatusMsg'] = ''; // Assume no error
$R['Data'] = ''; // Assume error

// Prepare to open the process
$xDesc = array(
	0 => array("pipe", "r"),  // 0 => writeable (by me) handle connected to child stdin
	1 => array("pipe", "w"),  // 1 => readable (by me) handle connected to child stdout
	2 => array("pipe", "w")	  // 2 => readable (by me) handle connected to child stderr
);

// Open the process (execute the command)
if ($Password == '') {$Proc = proc_open('funzip', $xDesc, $Pipes);}
else {$Proc = proc_open("funzip -$Password", $xDesc, $Pipes);}

// The process opened
if (is_resource($Proc)) {

	// Send the raw data to the unzip command and close the pipe
	fwrite($Pipes[0], $Data);
	fclose($Pipes[0]);

	// Read all data from unzip > STDOUT and close the pipe
	while (!feof($Pipes[1])) {
		$sOUT .= fgets($Pipes[1], 1024);
	}
	fclose($Pipes[1]);

	// Read all data from unzip > STDERR and close the pipe
	while (!feof($Pipes[2])) {
		$sERR .= fgets($Pipes[2], 1024);
	}
	fclose($Pipes[2]);

	// Close the process
	$return_value = proc_close($Proc);

	// Error Trap: The command generated an error: Return StatusCode 2 and the error message and exit now
	if (strlen($sERR) > 0) {
		$R['StatusCode'] = 2;
		$R['StatusMsg'] = $sERR;
		$R['Data'] = $sOUT;
		return $R;
	}

	// No errors occured, return the uncompressed data and exit now
	$R['Data'] = $sOUT;
	return $R;

}

// Error Trap: PHP could not start the process: Return StatusCode 1 and exit now
$R['StatusCode'] = 1;
return $R;

}
 


The Captian
Today they call you "crazy". Tomorrow they call you "ahead of your time."
Global Skywatch Learn about Chemtrails - You're breathing them now!
OnlyTheBestHerbs.com World-class supplements
Mercury Talk Why you are sick.
OneUp Domains Domains, Hosting, Email
1-800-358-4278 (U.S. & Canada)