php不解压读取压缩包目录,读取压缩包内文件

 /**
     * 读取压缩包目录
     */
    public function getDecompression()
    {
        $url = public_path('uxradar.zip');
        $zipper = new \ZipArchive();
        $zipStatus = $zipper->open($url);
        if ($zipStatus !== true) {
            throw new \Exception('Could not open ZIP file. Error code: ' . $zipStatus);
        }
        $filesInside = [];
        for ($i = 0; $i < $zipper->count(); $i++) {
            array_push($filesInside, $zipper->getNameIndex($i));
        }
        $zipper->close();
        return $filesInside;
    }

    /**
     * 代码压缩包详细文件信息
     * @param int $id
     * @return array
     */
    public function getDecompressionDetail()
    {
        $zipPath = public_path('uxradar.zip');
        $content = false;
        $zip = new \ZipArchive();
        if ($zip->open($zipPath) === true) {
            $content = $zip->getFromName('uxradar/1.txt');
            $content = $content && iconv('GBK', 'UTF-8', $content);
            $zip->close();
        }
        return $this->success($content);
    }

  一定要确定自己的php环境安装了zip扩展,文件目录:

 

posted @ 2020-11-17 18:20  明明一颗大白菜  阅读(894)  评论(0编辑  收藏  举报
<-- -->