Skip to content

Commit

Permalink
完善导入插件功能
Browse files Browse the repository at this point in the history
  • Loading branch information
weichaoduo committed Jul 8, 2021
1 parent 20d412d commit 1a772f8
Show file tree
Hide file tree
Showing 15 changed files with 557 additions and 135 deletions.
92 changes: 92 additions & 0 deletions app/classes/UploadLogic.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,98 @@ public function move($fieldName, $fileType, $uuid = '', $originName = '', $origi
return $this->uploadError('上传失败', 4);
}

/**
* @param $fieldName
* @return array
*/
public function movePluginZip($fieldName)
{
//文件保存目录URL
//$saveUrl = ATTACHMENT_URL;
$savePath = STORAGE_PATH . "plugin_zip/";
$relatePath = '';
//PHP上传失败
if ($_FILES[$fieldName]['error'] != UPLOAD_ERR_OK) {
switch ($_FILES[$fieldName]['error']) {
case '1':
$error = '超过php.ini允许的大小';
break;
case '2':
$error = '超过表单允许的大小';
break;
case '3':
$error = '图片只有部分被上传';
break;
case '4':
$error = '没有文件被上传';
break;
case '6':
$error = '找不到临时目录';
break;
case '7':
$error = '写文件到硬盘出错';
break;
case '8':
$error = '不允许的扩展名';
break;
case '999':
default:
$error = '未知错误。';
}
return $this->uploadError($error, (int)$_FILES[$fieldName]['error']);
}
//有上传文件时
if (empty($_FILES) === false) {
//原文件名
$fileName = $_FILES[$fieldName]['name'];
if (empty($originName)) {
$originName = $fileName;
}
//服务器上临时文件名
$tmpName = $_FILES[$fieldName]['tmp_name'];
//检查文件名
if (!$fileName) {
return $this->uploadError('请选择文件');
}
//检查目录
if (@is_dir($savePath) === false) {
return $this->uploadError("上传目录不存在");
}
//检查目录写权限
if (@is_writable($savePath) === false) {
return $this->uploadError("上传目录没有写权限");
}
//获得文件扩展名
$tempArr = explode(".", $fileName);
$fileExt = array_pop($tempArr);
$fileExt = trim($fileExt);
$fileExt = strtolower($fileExt);
if ($fileExt != 'zip') {
$msg = "上传文件的扩展名错误.只允许zip格式.";
return $this->uploadError($msg);
}
//新文件名
$newFileName = date("YmdHis") . '_' . rand(10000, 99999) . '.' . $fileExt;
//移动文件
$filePath = $savePath . $newFileName;
if (move_uploaded_file($tmpName, $filePath) === false) {
return $this->uploadError("上传文件失败.");
}
@chmod($filePath, 0644);
//$fileUrl = $saveUrl . $newFileName;
$relatePath .= $newFileName;
$uuid = quickRandom() . mt_rand(10000, 999999);
return [
'message' => '上传成功',
'error' => 0,
'url' => '',
'filename' => $originName,
'relate_path' => $relatePath,
'uuid' => $uuid
];
}
return $this->uploadError('上传失败', 4);
}
/**
* 统一返回上传返回值
* @param string $msg
Expand Down
13 changes: 2 additions & 11 deletions app/ctrl/BaseCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,17 +605,8 @@ public function getPluginDirArr($pluginDir)
public function loadPlugin()
{
$pluginModel = new PluginModel();
$plugins = $pluginModel->getRows('id, name, title');
$pluginsKeyArr = array_column($plugins, null, 'name');
$dirPluginArr = $this->getPluginDirArr(PLUGIN_PATH);
foreach ($dirPluginArr as $dirName => $item) {
if (!isset($pluginsKeyArr[$dirName])) {
$tmp = $item;
$tmp['status'] = PluginModel::STATUS_UNINSTALLED;
$tmp['is_system'] = '0';
$plugins[] = $tmp;
}
}
$plugins = $pluginModel->getRows('id, name, title, status',['status'=>PluginModel::STATUS_INSTALLED]);

if ($plugins) {
foreach ($plugins as $plugin) {
$pluginName = $plugin['name'];
Expand Down
Loading

0 comments on commit 1a772f8

Please sign in to comment.