php system 调用命令压缩文件

对一批文件进行压缩处理,采用system 调用linux 压缩命令进行文件压缩。

命令公用代码:

function addZip($webdocs, $zipfile, $param, $file){
    system("cd $webdocs; tar $param $zipfile \"".$file ."\"",$output);    
   if ($output == 0){
       echo " OK\r\n";    
       return 0;
   }else {
       echo " Fail:".(int)$output."\r\rn";
       return -1;
   }
}

主要考虑的是,压缩文件不存在 cf .压缩文件已存在,rf

$zipfile = "/root/admintool_zip_resources_$date.tar.gz";
$webdocs = "/webdocs";        
$isfirst = true;

if
($isfirst == true){ $isfirst = false; addZip($webdocs, $zipfile, "cf", trim($val['resource_links'])); }else { addZip($webdocs, $zipfile, "rf", trim($val['resource_links'])); }

 

posted @ 2014-08-08 14:24  timily  阅读(342)  评论(0编辑  收藏  举报