From 29c05d2d24fb31f20947e8d978bf32d760d12775 Mon Sep 17 00:00:00 2001 From: taoser Date: Wed, 7 Jul 2021 17:24:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E6=96=87=E4=BB=B6=E6=A3=80?= =?UTF-8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Upgrade.php | 22 ++++++++++++++++++++-- app/admin/view/upgrade/index.html | 8 ++------ app/common/lib/ZipFile.php | 2 +- config/taoler.php | 2 +- extend/taoler/com/Files.php | 22 ++++++++++++++++++++++ 5 files changed, 46 insertions(+), 10 deletions(-) diff --git a/app/admin/controller/Upgrade.php b/app/admin/controller/Upgrade.php index 0b42e73..ffdfda9 100644 --- a/app/admin/controller/Upgrade.php +++ b/app/admin/controller/Upgrade.php @@ -233,10 +233,28 @@ class Upgrade extends AdminController //删除sql语句 unlink($upSql); } - - //升级PHP + + //升级PHP if(is_dir($zipPath)) { + //升级前的写入文件权限检查 + $allUpdateFiles = Files::getAllFile($zipPath); + + if (empty($allUpdateFiles)) return json(['code' => -1, 'msg' => '无可更新文件。']); + $checkString = ''; + foreach ($allUpdateFiles as $updateFile) { + $coverFile = ltrim(str_replace($zipPath, '', $updateFile), DIRECTORY_SEPARATOR); + $dirPath = dirname('../'.$coverFile); + if (file_exists('../'.$coverFile)) { + if (!is_writable('../'.$coverFile)) $checkString .= $coverFile . ' [' . '无写入权限' . ']
'; + } else { + if (!is_dir($dirPath)) @mkdir($dirPath, 0777, true); + if (!is_writable($dirPath)) $checkString .= $dirPath . ' [' . '无写入权限' . ']
'; + } + } + + if (!empty($checkString)) return json(['code' => -1, 'msg' => $checkString]); + $cpRes = Files::copyDirs($zipPath,$this->root_dir); $cpData = $cpRes->getData(); //更新失败 diff --git a/app/admin/view/upgrade/index.html b/app/admin/view/upgrade/index.html index 87959e9..53da15f 100644 --- a/app/admin/view/upgrade/index.html +++ b/app/admin/view/upgrade/index.html @@ -141,12 +141,8 @@ }); } else { layer.close(load); - layer.open({ - title:'升级失败', - content:data.msg, - icon:5, - anim:6 - }); + layer.alert(data.msg,{icon:5,title:'更新失败', area:['50%', '70%']}); + return false; } } ); diff --git a/app/common/lib/ZipFile.php b/app/common/lib/ZipFile.php index bda9532..734e01b 100644 --- a/app/common/lib/ZipFile.php +++ b/app/common/lib/ZipFile.php @@ -43,7 +43,7 @@ class ZipFile if(file_exists($save_path)) { if($overwrite === true){ - echo $file_name . '
';	
+								//echo $file_name . '
';	
 								$file_size = zip_entry_filesize($zip);
 								$file = zip_entry_read($zip, $file_size);
 								$fpc = file_put_contents($save_path, $file);
diff --git a/config/taoler.php b/config/taoler.php
index 476a436..83724f3 100644
--- a/config/taoler.php
+++ b/config/taoler.php
@@ -7,7 +7,7 @@ return [
 	//应用名,此项不可更改
 	'appname'	=> 'TaoLer',
     //版本配置
-    'version'   => '1.7.13',
+    'version'   => '1.7.14',
 	//加盐
 	'salt'		=> 'taoler',
 	//数据库备份目录
diff --git a/extend/taoler/com/Files.php b/extend/taoler/com/Files.php
index 54482c7..83c2ec4 100644
--- a/extend/taoler/com/Files.php
+++ b/extend/taoler/com/Files.php
@@ -34,6 +34,28 @@ class Files
 			 return $arr;
 		}
 	}
+	
+	/**
+     * 列出目录下的所有文件,包括子目录文件,不包含sql目录
+     * @param $dirName
+     * @return array
+     */
+    public static function getAllFile($dirName)
+    {
+        //$dirName    = str_replace('..', '', rtrim($dirName, '/\\'));
+        $fileArray  = [];
+        if (is_dir($dirName)) {
+            $dh = scandir($dirName);
+            foreach ($dh as $file) {
+                if (!in_array($file, ['.', '..', 'runtime', '.DS_Store'])) {
+                    $path = $dirName . DIRECTORY_SEPARATOR . $file;
+                    if (!is_dir($path)) $fileArray[] = $path;
+                    $fileArray = array_merge($fileArray, self::getAllFile($path));
+                }
+            }
+        }
+        return $fileArray;
+    }
 
     /**
      * 创建文件夹及子文件夹