php 压缩文件

ZipArchive为php自带的 5.2上即有


TP

//压缩文件
	public function zipFiles()
	{
		$fileList = array(
				//"e:/tmp/log.txt",
				//"e:/tmp/weixin.class.php"

				"/data/web/sas/Public/DownloadZip/1.txt",
				"/data/web/sas/Public/DownloadZip/2.txt"

		);
		$md5_str = (md5(uniqid(microtime(true),true)).rand(1,20000));
		$filename = "/data/web/sas/Public/DownloadZip/".$md5_str.".zip";
		$zip = new \ZipArchive();
		$zip->open($filename,\ZipArchive::CREATE);   //打开压缩包
		foreach($fileList as $file){
			$zip->addFile($file,basename($file));   //向压缩包中添加文件
		}
		$zip->close();  //关闭压缩包

	}


猜你喜欢

转载自blog.csdn.net/a9925/article/details/78912352