zip($path_parts['filename'], $path_parts['dirname']); } if ($zip) {//压缩完成 //echo '压缩用时:'.(time()-$start).PHP_EOL; $tagetDat = $targetDir . '/' . $path_parts['filename'] . '.zip'; //echo $tagetDat . PHP_EOL; //删除本地dat文件 @unlink($path_parts['dirname'] . '/' . $path_parts['filename'] . '.dat'); $datRes = Zmcoding\FtpFile::getInstance($config)->up_file($zip, $tagetDat); if ($datRes) { $md5Res = Zmcoding\FtpFile::getInstance($config)->up_file($v, $targetDir . '/' . $path_parts['basename']); //md5文件 if ($md5Res) { debug_log('upload_info', json_encode($targetDir . '/' . $path_parts['basename'], JSON_UNESCAPED_UNICODE)); } debug_log('upload_info', json_encode($tagetDat, JSON_UNESCAPED_UNICODE)); } } } // sleep(3); } } public function zip( $name, $path ){ //压缩 if (!file_exists($path)) { return false; } $current_dir = opendir($path); $needzip = '';//需要压缩的文件 while (($file = readdir($current_dir)) !== false) { $sub_dir = $path . DIRECTORY_SEPARATOR . $file; if ($file == '.' || $file == '..') { continue; } if (is_file($sub_dir)) { //如果是.dat文件,进行赋值 $pathinfo = pathinfo($file); // var_dump($pathinfo); if ($pathinfo['extension'] == 'dat' && $pathinfo['filename'] == $name) { $needzip = $file; } } } if ($needzip == '') { return false; } // var_dump($files);exit; $zip_filename = $path . '/' . $name . '.zip'; @unlink($zip_filename); if (!file_exists($zip_filename)) { touch($zip_filename); $zip = new \ZipArchive(); $ret = $zip->open($zip_filename, \ZipArchive::OVERWRITE); if ($ret !== true) { return false; } else { // if (!empty($files)) { // foreach ($files as $file) { $zip->addFile($path . '/' . $needzip, $needzip); // @unlink($path . '/' . $name . '.dat'); // } // } $zip->close(); } } return $zip_filename; } }