经测试代码如下:
/**
* 压缩zip文件
*
* @param
* @author 编程之家 jb51.cc jb51.cc
**/
function emZip($orig_fname,$content) {
if (!class_exists('ZipArchive',FALSE)) {
return false;
}
$zip = new ZipArchive();
$tempzip = EMLOG_ROOT . '/content/cache/emtemp.zip';
$res = $zip->open($tempzip,ZipArchive::CREATE);
if ($res === TRUE) {
$zip->addFromString($orig_fname,$content);
$zip->close();
$zip_content = file_get_contents($tempzip);
unlink($tempzip);
return $zip_content;
} else {
return false;
}
}