public function exten() { // 设置要打包的文件夹路径 $folderPath = "chrome-proxy-extensions/1311"; // 设置压缩后的 zip 文件名 $zipFileName = "1311.zip"; // 创建一个 ZipArchive 对象 $zip = new ZipArchive(); if ($zip->open($zipFileName, ZipArchive::CREATE | ZipArchive::OVERWRITE) === TRUE) { // 添加文件到 zip 文件中 $zip->addFile($folderPath . "/background.js", "1311/background.js"); $zip->addFile($folderPath . "/manifest.json", "1311/manifest.json"); $zip->close(); // 提供下载链接 header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename="' . $zipFileName . '"'); header('Content-Length: ' . filesize($zipFileName)); readfile($zipFileName); // 删除临时的 zip 文件 unlink($zipFileName); } else { echo 'Failed to create zip file.'; } }
^_^ 亲爱的客官,如果您觉得本文对您有好处,请移动你的鼠标点点下面的关注我,一起学习,一起分享.~ ^_^