欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

php压缩和解压zip

程序员文章站 2022-05-25 23:31:40
...

php压缩和解压zip 无 // 压缩zip$zip_c = new ZipArchive;$res = $zip_c-open('./g_file/file.zip', ZipArchive::CREATE);if ($res === TRUE) { $zip_c-addFile('./g_file/grain.txt','grain.txt'); // 将文件添加的压缩包中$zip_c-addFile('./g_file/granary

php压缩和解压zip
      // 压缩zip
	$zip_c = new ZipArchive;	
	$res = $zip_c->open('./g_file/file.zip', ZipArchive::CREATE);
	if ($res === TRUE) { 
		$zip_c->addFile('./g_file/grain.txt','grain.txt');  // 将文件添加的压缩包中
		$zip_c->addFile('./g_file/granary.txt','granary.txt');
		$zip_c->addFile('./g_file/sensor.txt','sensor.txt');
		$zip_c->addFile('./g_file/data.txt','data.txt'); 
		$zip_c->close(); //关闭
		$url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]; 
		$dir_url_http=dirname($url).'/';
		operation_log($uname,"下载数据");
		echo "{\"s\":\"0\",\"url\":\"{$dir_url_http}g_file/file.zip\"}";
	}

       //  解压zip
		$zip = new ZipArchive;
		$res = $zip->open('./u_file/file.zip');
		if ($res === TRUE) {
			$zip->extractTo('./u_file/');
			$zip->close();
                 }