It's me ;-)

Một PHP class tạo file ZIP

Tôi đang phải làm  chức năng nén/giải nén trong dự án hiện tại. Giải nén thì đã làm xong rồi, còn nén nữa là xong. Zip library của PHP hỗ trợ chức năng zip hơi bị kém, cái cơ bản nhất là cũng ngại phải viết => search & thấy class này khá nhẹ để nén 1 folder.

file();
	
	function rec_listFiles( $from = '.')
	{
		global $zipfile, $filedata;
		
		if(! is_dir($from))
			return false;
	   		
		if( $dh = opendir($from))
		{
			while( false !== ($file = readdir($dh)))
			{
				// Skip '.' and '..'
				if( $file == '.' || $file == '..')
					continue;
				$path = $from . '/' . $file;
				if( is_dir($path) ) {
					$zipfile->add_dir($path);
					rec_listFiles($path);
				}
				else {
					$filedata = implode("", file($path));
					$zipfile->add_file($filedata, $path);
				}
			}
			closedir($dh);
		}
	}
?>

Tạm đáp ứng yêu cầu 🙂

Source: http://www.devco.net/archives/2005/05/24/creating_zip_files_with_php.php

5 thoughts on “Một PHP class tạo file ZIP

  1. hey guys thanks alot for all the insight. really liked the section. and iam starting to give it a shot. if you receive any different nice books or places on the content, love to hear from you. thanks again.

Leave a Reply to Movias Cancel reply

Your email address will not be published. Required fields are marked *