
 Marcus Hjortsberg - 2011-08-10 14:46:46
I have made a little change to the code so that the files is saved directly in the zip file without the folder hierarchy.
I have also put a little extra code so that some file extensions can be excluded.
But I think it can be problems if the folder you want ti zip contains sub folders, but this is just a thought...not tested...I only have the need to zip folders without sub folders at the moment...
The code...(replace the zipDirectory function)
public function zipDirectory($dirName, $outputDir) {
		if (!is_dir($dirName)){
			trigger_error("CreateZipFile FATAL ERROR: Could not locate the specified directory $dirName", E_USER_ERROR);
		}
		$tmp=$this->parseDirectory($dirName);
		$count=count($tmp);
		//$this->addDirectory($outputDir);
		for ($i=0;$i<$count;$i++){
			$fileToZip=trim($tmp[$i]);
			$newOutputDir=substr($fileToZip,0,(strrpos($fileToZip,'/')+1));
			$outputDir=$outputDir.$newOutputDir;
			
			 $parts = explode(".", $fileToZip);
			 if (is_array($parts) && count($parts) > 1)
			 {
				$extension = end($parts);
				if ($extension == "zip" OR $extension == "ZIP")
				{}
				else
				{
					$parts2 = explode("/", $fileToZip);
					$file = end($parts2);
					$fileContents=file_get_contents($fileToZip);
					$this->addFile($fileContents,$file);
				}
			}
		}
	}