- // 压缩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();
- }
- //该片段来自于http://www.codesnippet.cn/detail/2411201411029.html
来源: http://www.codesnippet.cn/detail/2411201411029.html