PHP解压文件

5年以前  |  阅读数:927 次  |  编程语言:PHP 

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;
    }

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8