PHP Code
// Purpose
//	Used to compress data using the PK zip format.
//	Supports password-protected data as well.
// Parameters
//	Data (String) = The data we want to compress.
//	Password (Optional String) = The password to use to protect the file.
//		If this is not passed, no password is passed to the zip command.
// 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 compressed contents of the specified file.
//	If the zip function did not start properly (it was never considered a resource by PHP):
//		StatusCode = -1
//		StatusMsg = ''
//		Data = ''
//	No other status codes are returned because there is no (known) way to get the exit code
//		from the program to PHP. We must, therefore, "assume" that the program succeeded.
// Version History
//	1.0 4/25/2004 Tested by Russ Tanner
//		This was tested with zip version 2.3 (UNIX).
//---
function Zip($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('zip', $xDesc, $Pipes);}
else {$Proc = proc_open("zip -P $Password", $xDesc, $Pipes);}

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

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

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

	// Read all data from zip > 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: I will insert an error trap here if a method to catch the "exit code" of
	// the Zip program (or any command line program) becomes known. Until then, we just assume success.
	//if ($return_value != 0) {
		//$R['StatusCode'] = $return_value;
		//$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)