
 Rosen - 2009-01-25 11:48:18
Just add these functions in the createZip class.	
<------------   [CODE]   ------------>
public function zipDir($dir, $mainObj = ''){
		
		if( ($mainObj != '') && (substr($mainObj, -1) != '/') ) {
			$mainObj .= '/';
		}
		
		if( ($dir != null) && (substr($dir, -1) == '/') ) {
			$dir = substr($dir, 0, (strlen($dir)-2) ); // I don't know why i did this :D
		}
		
		$this -> addDirectory($mainObj);
		$d = dir($dir);
		while (false !== ($entry = $d->read())) {
			if($entry != '.' && $entry != '..' && $entry != 'Thumbs.db'){
				if(is_dir($dir.'/'.$entry)){
					$this->zipDir($dir.'/'.$entry, $mainObj.$entry);
					#echo '<b>DIR: '.$dir.'/'.$entry.'</b><br>';
				}else{
					$fileContents = file_get_contents($dir.'/'.$entry);
					$this -> addFile($fileContents, $mainObj.$entry);
					#echo '<b>FILE: '.$dir.'/'.$entry.'</b><br>';
				}
			}
		}
		$d->close();
	}
	public function zipFiles($zipList){	
	
		foreach($zipList as $toZip){
			if(is_dir($toZip)){
				$this->zipDir($toZip);
			}else{
				$fileContents = file_get_contents($toZip);  
				$this -> addFile($fileContents, $toZip); 
			}
		}
	
	}
<------------   [/CODE]   ------------>
The usage is simple. Just do this:
<------------   [CODE]   ------------>
$zipFiles = array('dir1', 'dir2', 'file1', 'dir3', 'file2'); 
$createZip -> zipFiles($zipFiles);
<------------   [/CODE]   ------------>
Use the full path of the files, e.g. $_SERVER['DOCUMENT_ROOT'].'/www/myDirToZip', or just the relative, e.g. '/www/myDirToZip'.
Don't use links like this '../../myDirToZip'.