storage_path("cache");為路徑函數,在使用時,需要替換成自己的方法,以便使其解壓到指定目錄。
function unzipFile($filePath)
{
$destDir = "";
try {
$zip = new ZipArchive();
if ($zip->open($filePath, ZipArchive::FL_COMPRESSED) === TRUE) {
$cacheDir = storage_path("cache");
$destDir = $cacheDir . "/temp_zip_dir";
mkdir($destDir);
$zip->extractTo($destDir);
}
$zip->close();
} catch (\Exception $e) {
}
return $destDir;
}