/** * 读取压缩包目录 */ public function getDecompression() { $url = public_path('uxradar.zip'); $zipper = new ipArchive(); $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 ipArchive(); 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扩展,文件目录: