开发php项目管理系统,由于是新项目且已经部署在生产环境,导致需要根据实际使用情况,进行及时的功能升级或bug修复。
<form lay-filter="component-form-group"> <div> <div>系统升级</div> <div> <div> <label for="zip_url">程序包</label> <div><input type="text" id="zip_url" name="zip_url" lay-verify="required" readonly></div> <div><button type="button" id="uploadImg">上传压缩包</button></div> <div> <a lay-filter="save" id="L_add" lay-submit="">确定升级</a></div> <div><span>*</span> 支持.zip、.rar、.gz格式压缩包</div> </div> </div> </div> </form>
//上传压缩包; var loadingIndex; upload.render({ elem: "#uploadImg" , url: "?m=Zip&a=zipDeal&act=upImg&token="+upToken , multiple: false , size: 102400 , accept: "file" , exts: "zip|rar|gz" , number: 1 , before: function (obj) { //console.log(obj); loadingIndex = layer.load(); } , done: function (res) { layer.close(loadingIndex); if (res.code == 1) { layer.msg(res.msg); }else{ $("#zip_url").val(res.imgUrl); } } });
//读取信息; case "update"; $zip_url = $_POST["zip_url"]; //压缩包解压; if (extension_loaded("zip")) { $dest = "./"; /*解压缩操作*/ unzip($zip_url, $dest); unlink($zip_url); $res["code"] = "1"; $res["msg"] = "解压完毕,目录已覆盖升级"; die(json_encode_lockdata($res)); } else { $res["code"] = "0"; $res["msg"] = "请在php.ini中开启php_zip.dll"; die(json_encode_lockdata($res)); } break;
form.on("submit(save)", function () { $.ajax({ type: "post", url: "?m=Zip&a=zipDeal&act=update", async: true, data: { zip_url: $("#zip_url").val() }, dataType: "json", success: function (res) { if (res.code == 0) { layer.msg(res.msg, {icon: 1,time: 2000}); } else { layer.msg(res.msg, {icon: 1,time: 2000}, function () { location.reload(); }); } } }); return false; });
function unzip($zipName, $dest) { //检测要解压压缩包是否存在 if (!is_file($zipName)) { die("解压文件不存在,请确认压缩文件"); } //检测目标路径是否存在 if (!is_dir($dest)) { mkdir($dest, 0777, true); } $zip = new ZipArchive(); if ($zip->open($zipName)) { $zip->extractTo($dest); $zip->close(); return true; } else { return false; } }
到此这篇关于php ZipArchive解压缩实现后台管理升级问题详解的文章就介绍到这了,更多相关php ZipArchive内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!