1.composer require pclzip/pclzip
第3517行 $p_entry['filename'] = $p_path . "/" . $p_entry['filename'];
2.$p_entry['filename'] = mb_convert_encoding($p_entry['filename'], 'UTF-8', 'gb2312');
private function uploads($zipfile,$filepath,$company_id,$type){
include('./vendor/pclzip/pclzip/pclzip.lib.php');
$archive = new \PclZip($zipfile);
if ($archive->extract(PCLZIP_OPT_PATH, $filepath,
PCLZIP_OPT_REMOVE_PATH, 'install/release') == 0) {
die("Error : ".$archive->errorInfo(true));
}
$company_name = M("company")->where("id=$company_id")->getField('name');
if($type == 1){
$staff_company = "$company_name/毕业证";
}elseif ($type == 2){
$staff_company = "$company_name/保密协议";
}elseif($type == 3){
$staff_company = "$company_name/劳动合同";
}elseif($type == 4){
$staff_company = "$company_name/身份证";
}elseif($type == 5) {
$staff_company = "$company_name/离职证明";
}else{
$this->error('上传类型错误');
}
$file = scandir($filepath);
foreach ($file as $key=>$value){
if (!is_dir($filepath.$value)){
continue;
}
$copy = $filepath.$value;
}
$root = $_SERVER['DOCUMENT_ROOT'];
$path = "/Uploads/Staff/$staff_company";
$result = false;
$this->copy_to_file($copy,$root . $path, $result);
if ($result == true){
$this->deldir($filepath);
$this->success("上传成功");
}else{
$this->error("上传失败");
}
}
private function copy_to_file($old_dir,$new_dir,&$result=false,$quanxian=0777){
if(!is_dir($new_dir)){
@mkdir($new_dir,$quanxian,true);
}
$res = '';
$temp = scandir($old_dir);
if(is_array($temp) && count($temp)>2){
unset($temp[0],$temp[1]);
foreach($temp as $key=>$val){
$file_url=$old_dir.DIRECTORY_SEPARATOR.$val;
$xin_dir = $new_dir.DIRECTORY_SEPARATOR.$val;
if(is_dir($file_url)){
$res = $this->copy_to_file($file_url,$xin_dir,$result);
}elseif(is_file($file_url)){
$res = copy($file_url,$xin_dir);
}
if ($res == true) {
$result = true;
}
}
}
return $res;
}
private function deldir($dir) {
$dh = opendir($dir);
while ($file=readdir($dh)) {
if($file !="." && $file!="..") {
$fullpath=$dir."/".$file;
if(!is_dir($fullpath)) {
unlink($fullpath);
} else {
$this->deldir($fullpath);
}
}
}
closedir($dh);
if(rmdir($dir)) {
return true;
} else {
return false;
}
}
 
|