php ZipArchive 中文乱码
public static function unzip_file(string $zipName,string $dest){
        //检测要解压压缩包是否存在
        if(!is_file($zipName)){
            return false;
        }
        //检测目标路径是否存在
        if(!is_dir($dest)){
            mkdir($dest,0777,true);
        }
        $zip=new ZipArchive();
        $res = $zip->open($zipName);
        if ($res !== true){
            throw new \Exception('打开压缩包失败');
        }

        // 加入此段↓
        $fileNum = $zip->numFiles;
        for ($i = 0; $i < $fileNum; $i++) {
            $statInfo = $zip->statIndex($i, ZipArchive::FL_ENC_RAW);
            $zip->renameIndex($i, iconv('GBK', 'utf-8//IGNORE', $statInfo['name']));
        }
        $zip->close();
        $zip->open($zipName);
        // 截至↑
        $zip->extractTo($dest);
        $zip->close();
    }
上一篇
下一篇