升级文件检测

This commit is contained in:
taoser 2021-07-07 17:24:25 +08:00
parent 032426f71e
commit 29c05d2d24
5 changed files with 46 additions and 10 deletions

View File

@ -234,9 +234,27 @@ class Upgrade extends AdminController
unlink($upSql); unlink($upSql);
} }
//升级PHP //升级PHP
if(is_dir($zipPath)) 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 . '&nbsp;[<span class="text-red">' . '无写入权限' . '</span>]<br>';
} else {
if (!is_dir($dirPath)) @mkdir($dirPath, 0777, true);
if (!is_writable($dirPath)) $checkString .= $dirPath . '&nbsp;[<span class="text-red">' . '无写入权限' . '</span>]<br>';
}
}
if (!empty($checkString)) return json(['code' => -1, 'msg' => $checkString]);
$cpRes = Files::copyDirs($zipPath,$this->root_dir); $cpRes = Files::copyDirs($zipPath,$this->root_dir);
$cpData = $cpRes->getData(); $cpData = $cpRes->getData();
//更新失败 //更新失败

View File

@ -141,12 +141,8 @@
}); });
} else { } else {
layer.close(load); layer.close(load);
layer.open({ layer.alert(data.msg,{icon:5,title:'更新失败', area:['50%', '70%']});
title:'升级失败', return false;
content:data.msg,
icon:5,
anim:6
});
} }
} }
); );

View File

@ -43,7 +43,7 @@ class ZipFile
if(file_exists($save_path)) { if(file_exists($save_path)) {
if($overwrite === true){ if($overwrite === true){
echo $file_name . '<pre />'; //echo $file_name . '<pre />';
$file_size = zip_entry_filesize($zip); $file_size = zip_entry_filesize($zip);
$file = zip_entry_read($zip, $file_size); $file = zip_entry_read($zip, $file_size);
$fpc = file_put_contents($save_path, $file); $fpc = file_put_contents($save_path, $file);

View File

@ -7,7 +7,7 @@ return [
//应用名,此项不可更改 //应用名,此项不可更改
'appname' => 'TaoLer', 'appname' => 'TaoLer',
//版本配置 //版本配置
'version' => '1.7.13', 'version' => '1.7.14',
//加盐 //加盐
'salt' => 'taoler', 'salt' => 'taoler',
//数据库备份目录 //数据库备份目录

View File

@ -35,6 +35,28 @@ class Files
} }
} }
/**
* 列出目录下的所有文件,包括子目录文件,不包含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;
}
/** /**
* 创建文件夹及子文件夹 * 创建文件夹及子文件夹
* @param $path * @param $path