From fc137da5c7f499a8abc1f68aedaaa01c4101a0f9 Mon Sep 17 00:00:00 2001 From: devil_gong Date: Mon, 25 Mar 2019 10:57:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E7=94=A8=E6=89=93=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/service/PluginsAdminService.php | 103 +++++++++++++++++++- extend/base/FileUtil.php | 48 +++++++++ 2 files changed, 149 insertions(+), 2 deletions(-) diff --git a/application/service/PluginsAdminService.php b/application/service/PluginsAdminService.php index 500288e30..b559e1af2 100755 --- a/application/service/PluginsAdminService.php +++ b/application/service/PluginsAdminService.php @@ -1018,8 +1018,107 @@ php; return DataReturn('应用不存在', -10); } - // 开始打包 - return DataReturn('开发中', -10); + // 目录不存在则创建 + $new_dir = ROOT.'runtime'.DS.'data'.DS.'plugins_package'.DS.$plugins; + \base\FileUtil::CreateDir($new_dir); + + // 复制包目录 - 控制器 + $old_dir = APP_PATH.'plugins'.DS.$plugins; + if(is_dir($old_dir)) + { + if(\base\FileUtil::CopyDir($old_dir, $new_dir.DS.'_controller_'.DS.$plugins) != true) + { + return DataReturn('项目包复制失败[控制器]', -2); + } + } + + // 复制包目录 - 视图 + $old_dir = APP_PATH.'plugins'.DS.'view'.DS.$plugins; + if(is_dir($old_dir)) + { + if(\base\FileUtil::CopyDir($old_dir, $new_dir.DS.'_view_'.DS.$plugins) != true) + { + return DataReturn('项目包复制失败[视图]', -2); + } + } + + // 复制包目录 - css + $old_dir = ROOT.'public'.DS.'static'.DS.'plugins'.DS.'css'.DS.$plugins; + if(is_dir($old_dir)) + { + if(\base\FileUtil::CopyDir($old_dir, $new_dir.DS.'_css_'.DS.$plugins) != true) + { + return DataReturn('项目包复制失败[css]', -2); + } + } + + // 复制包目录 - js + $old_dir = ROOT.'public'.DS.'static'.DS.'plugins'.DS.'js'.DS.$plugins; + if(is_dir($old_dir)) + { + if(\base\FileUtil::CopyDir($old_dir, $new_dir.DS.'_js_'.DS.$plugins) != true) + { + return DataReturn('项目包复制失败[js]', -2); + } + } + + // 复制包目录 - images + $old_dir = ROOT.'public'.DS.'static'.DS.'plugins'.DS.'images'.DS.$plugins; + if(is_dir($old_dir)) + { + if(\base\FileUtil::CopyDir($old_dir, $new_dir.DS.'_images_'.DS.$plugins) != true) + { + return DataReturn('项目包复制失败[images]', -2); + } + } + + // 复制包目录 - uploadimages + $old_dir = ROOT.'public'.DS.'static'.DS.'upload'.DS.'images'.DS.'plugins_'.$plugins; + if(is_dir($old_dir)) + { + if(\base\FileUtil::CopyDir($old_dir, $new_dir.DS.'_uploadimages_'.DS.'plugins_'.$plugins) != true) + { + return DataReturn('项目包复制失败[uploadimages]', -2); + } + } + + // 复制包目录 - uploadvideo + $old_dir = ROOT.'public'.DS.'static'.DS.'upload'.DS.'video'.DS.'plugins_'.$plugins; + if(is_dir($old_dir)) + { + if(\base\FileUtil::CopyDir($old_dir, $new_dir.DS.'_uploadvideo_'.DS.'plugins_'.$plugins) != true) + { + return DataReturn('项目包复制失败[uploadvideo]', -2); + } + } + + // 复制包目录 - uploadfile + $old_dir = ROOT.'public'.DS.'static'.DS.'upload'.DS.'file'.DS.'plugins_'.$plugins; + if(is_dir($old_dir)) + { + if(\base\FileUtil::CopyDir($old_dir, $new_dir.DS.'_uploadfile_'.DS.'plugins_'.$plugins) != true) + { + return DataReturn('项目包复制失败[uploadfile]', -2); + } + } + + // 生成压缩包 + $zip = new \base\ZipFolder(); + if(!$zip->zip($new_dir.'.zip', $new_dir)) + { + return DataReturn('压缩包生成失败', -100); + } + + // 生成成功删除目录 + \base\FileUtil::UnlinkDir($new_dir); + + // 开始下载 + if(\base\FileUtil::DownloadFile($new_dir.'.zip', $plugins.'.zip')) + { + @unlink($new_dir.'.zip'); + } else { + return DataReturn('下载失败', -100); + } } } ?> \ No newline at end of file diff --git a/extend/base/FileUtil.php b/extend/base/FileUtil.php index c571a44c1..f502cc26f 100755 --- a/extend/base/FileUtil.php +++ b/extend/base/FileUtil.php @@ -301,5 +301,53 @@ class FileUtil copy($file_url, $aim_url); return true; } + + /** + * 文件下载 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2019-03-25 + * @desc description + * @param [string] $file_path [文件地址] + * @param [string] $show_name [显示名称] + */ + public static function DownloadFile($file_path, $show_name) + { + if(is_file($file_path)) + { + //打开文件 + $file = fopen($file_path,"r"); + + //返回的文件类型 + Header("Content-type: application/octet-stream"); + + //按照字节大小返回 + Header("Accept-Ranges: bytes"); + + //返回文件的大小 + Header("Accept-Length: ".filesize($file_path)); + + //这里设置客户端的弹出对话框显示的文件名 + Header("Content-Disposition: attachment; filename=".$show_name); + + //一次性将数据传输给客户端 + //echo fread($file, filesize($file_path)); + //一次只传输1024个字节的数据给客户端 + //向客户端回送数据 + $buffer = 1024; + + //判断文件是否读完 + while(!feof($file)) + { + //将文件读入内存 + $file_data = fread($file, $buffer); + //每次向客户端回送1024个字节的数据 + echo $file_data; + } + return true; + } + return false; + } } ?> \ No newline at end of file -- GitLab