SAE php 环境的zip压缩

<?php  
/**
 * 使用ZIP压缩文件或目录
 * @param  [string] $toName   压缩后的文件名
 * @param  [string] $fromName 被压缩的文件或目录名
 * @return [bool]             成功返回TRUE, 失败返回FALSE
 */
function zip($fromName, $toName)  
{
    if(!file_exists($fromName)){
        return 1;
    }
    $zipArc = new ZipArchive();
    if(!$ret = $zipArc->open($toName, ZipArchive::CREATE)){
        return 2;
    }
    $res = is_dir($fromName) ? $zipArc->addGlob("{$fromName}/*") : $zipArc->addFile($fromName);
    if(!$res){
        $zipArc->close();
        return 3;
    }
    $zipArc->close();
    return 4;
}
$tmp_file = SAE_TMP_PATH.'class.zip';
if ($ret = zip('install', $tmp_file)){  
    $ret = copy($tmp_file, 'class.zip');
    echo "success";
}
else{  
    echo "failed";
}