编辑器图片上传问题
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
"imageCompressBorder": 1600, /* 图片压缩最长边限制 */
|
"imageCompressBorder": 1600, /* 图片压缩最长边限制 */
|
||||||
"imageInsertAlign": "none", /* 插入的图片浮动方式 */
|
"imageInsertAlign": "none", /* 插入的图片浮动方式 */
|
||||||
"imageUrlPrefix": "", /* 图片访问路径前缀 */
|
"imageUrlPrefix": "", /* 图片访问路径前缀 */
|
||||||
"imagePathFormat": "/ueditor/php/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
"imagePathFormat": "./uploads/editor/image", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||||
/* {filename} 会替换成原文件名,配置这项需要注意中文乱码问题 */
|
/* {filename} 会替换成原文件名,配置这项需要注意中文乱码问题 */
|
||||||
/* {rand:6} 会替换成随机数,后面的数字是随机数的位数 */
|
/* {rand:6} 会替换成随机数,后面的数字是随机数的位数 */
|
||||||
/* {time} 会替换成时间戳 */
|
/* {time} 会替换成时间戳 */
|
||||||
@@ -26,14 +26,14 @@
|
|||||||
/* 涂鸦图片上传配置项 */
|
/* 涂鸦图片上传配置项 */
|
||||||
"scrawlActionName": "uploadscrawl", /* 执行上传涂鸦的action名称 */
|
"scrawlActionName": "uploadscrawl", /* 执行上传涂鸦的action名称 */
|
||||||
"scrawlFieldName": "upfile", /* 提交的图片表单名称 */
|
"scrawlFieldName": "upfile", /* 提交的图片表单名称 */
|
||||||
"scrawlPathFormat": "/ueditor/php/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
"scrawlPathFormat": "./uploads/editor/image", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||||
"scrawlMaxSize": 2048000, /* 上传大小限制,单位B */
|
"scrawlMaxSize": 2048000, /* 上传大小限制,单位B */
|
||||||
"scrawlUrlPrefix": "", /* 图片访问路径前缀 */
|
"scrawlUrlPrefix": "", /* 图片访问路径前缀 */
|
||||||
"scrawlInsertAlign": "none",
|
"scrawlInsertAlign": "none",
|
||||||
|
|
||||||
/* 截图工具上传 */
|
/* 截图工具上传 */
|
||||||
"snapscreenActionName": "uploadimage", /* 执行上传截图的action名称 */
|
"snapscreenActionName": "uploadimage", /* 执行上传截图的action名称 */
|
||||||
"snapscreenPathFormat": "/ueditor/php/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
"snapscreenPathFormat": "./uploads/editor/image", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||||
"snapscreenUrlPrefix": "", /* 图片访问路径前缀 */
|
"snapscreenUrlPrefix": "", /* 图片访问路径前缀 */
|
||||||
"snapscreenInsertAlign": "none", /* 插入的图片浮动方式 */
|
"snapscreenInsertAlign": "none", /* 插入的图片浮动方式 */
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
"catcherLocalDomain": ["127.0.0.1", "localhost", "img.baidu.com"],
|
"catcherLocalDomain": ["127.0.0.1", "localhost", "img.baidu.com"],
|
||||||
"catcherActionName": "catchimage", /* 执行抓取远程图片的action名称 */
|
"catcherActionName": "catchimage", /* 执行抓取远程图片的action名称 */
|
||||||
"catcherFieldName": "source", /* 提交的图片列表表单名称 */
|
"catcherFieldName": "source", /* 提交的图片列表表单名称 */
|
||||||
"catcherPathFormat": "/ueditor/php/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
"catcherPathFormat": "./uploads/editor/image", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||||
"catcherUrlPrefix": "", /* 图片访问路径前缀 */
|
"catcherUrlPrefix": "", /* 图片访问路径前缀 */
|
||||||
"catcherMaxSize": 2048000, /* 上传大小限制,单位B */
|
"catcherMaxSize": 2048000, /* 上传大小限制,单位B */
|
||||||
"catcherAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 抓取图片格式显示 */
|
"catcherAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 抓取图片格式显示 */
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
/* 上传视频配置 */
|
/* 上传视频配置 */
|
||||||
"videoActionName": "uploadvideo", /* 执行上传视频的action名称 */
|
"videoActionName": "uploadvideo", /* 执行上传视频的action名称 */
|
||||||
"videoFieldName": "upfile", /* 提交的视频表单名称 */
|
"videoFieldName": "upfile", /* 提交的视频表单名称 */
|
||||||
"videoPathFormat": "/ueditor/php/upload/video/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
"videoPathFormat": "./uploads/editor/video", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||||
"videoUrlPrefix": "", /* 视频访问路径前缀 */
|
"videoUrlPrefix": "", /* 视频访问路径前缀 */
|
||||||
"videoMaxSize": 102400000, /* 上传大小限制,单位B,默认100MB */
|
"videoMaxSize": 102400000, /* 上传大小限制,单位B,默认100MB */
|
||||||
"videoAllowFiles": [
|
"videoAllowFiles": [
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
/* 上传文件配置 */
|
/* 上传文件配置 */
|
||||||
"fileActionName": "uploadfile", /* controller里,执行上传视频的action名称 */
|
"fileActionName": "uploadfile", /* controller里,执行上传视频的action名称 */
|
||||||
"fileFieldName": "upfile", /* 提交的文件表单名称 */
|
"fileFieldName": "upfile", /* 提交的文件表单名称 */
|
||||||
"filePathFormat": "/ueditor/php/upload/file/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
"filePathFormat": "./uploads/editor/file", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||||
"fileUrlPrefix": "", /* 文件访问路径前缀 */
|
"fileUrlPrefix": "", /* 文件访问路径前缀 */
|
||||||
"fileMaxSize": 51200000, /* 上传大小限制,单位B,默认50MB */
|
"fileMaxSize": 51200000, /* 上传大小限制,单位B,默认50MB */
|
||||||
"fileAllowFiles": [
|
"fileAllowFiles": [
|
||||||
@@ -72,7 +72,7 @@
|
|||||||
|
|
||||||
/* 列出指定目录下的图片 */
|
/* 列出指定目录下的图片 */
|
||||||
"imageManagerActionName": "listimage", /* 执行图片管理的action名称 */
|
"imageManagerActionName": "listimage", /* 执行图片管理的action名称 */
|
||||||
"imageManagerListPath": "/ueditor/php/upload/image/", /* 指定要列出图片的目录 */
|
"imageManagerListPath": "./uploads/editor/image/", /* 指定要列出图片的目录 */
|
||||||
"imageManagerListSize": 20, /* 每次列出文件数量 */
|
"imageManagerListSize": 20, /* 每次列出文件数量 */
|
||||||
"imageManagerUrlPrefix": "", /* 图片访问路径前缀 */
|
"imageManagerUrlPrefix": "", /* 图片访问路径前缀 */
|
||||||
"imageManagerInsertAlign": "none", /* 插入的图片浮动方式 */
|
"imageManagerInsertAlign": "none", /* 插入的图片浮动方式 */
|
||||||
@@ -80,7 +80,7 @@
|
|||||||
|
|
||||||
/* 列出指定目录下的文件 */
|
/* 列出指定目录下的文件 */
|
||||||
"fileManagerActionName": "listfile", /* 执行文件管理的action名称 */
|
"fileManagerActionName": "listfile", /* 执行文件管理的action名称 */
|
||||||
"fileManagerListPath": "/ueditor/php/upload/file/", /* 指定要列出文件的目录 */
|
"fileManagerListPath": "./uploads/editor/file/", /* 指定要列出文件的目录 */
|
||||||
"fileManagerUrlPrefix": "", /* 文件访问路径前缀 */
|
"fileManagerUrlPrefix": "", /* 文件访问路径前缀 */
|
||||||
"fileManagerListSize": 20, /* 每次列出文件数量 */
|
"fileManagerListSize": 20, /* 每次列出文件数量 */
|
||||||
"fileManagerAllowFiles": [
|
"fileManagerAllowFiles": [
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ class Ueditor{
|
|||||||
|
|
||||||
public function __construct($uid = '') {
|
public function __construct($uid = '') {
|
||||||
//uid 为空则导入当前会话uid
|
//uid 为空则导入当前会话uid
|
||||||
if(''===$uid) $this->uid = session('user_auth.uid');
|
if ('' === $uid) {
|
||||||
|
$this->uid = session('user_auth.uid');
|
||||||
|
}
|
||||||
|
|
||||||
//导入设置
|
//导入设置
|
||||||
$this->config = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents(APP_PATH . "ueditor.json")), true);
|
$this->config = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents(APP_PATH . "ueditor.json")), true);
|
||||||
@@ -32,7 +34,7 @@ class Ueditor{
|
|||||||
$config = array(
|
$config = array(
|
||||||
"pathFormat" => $this->config['imagePathFormat'],
|
"pathFormat" => $this->config['imagePathFormat'],
|
||||||
"maxSize" => $this->config['imageMaxSize'],
|
"maxSize" => $this->config['imageMaxSize'],
|
||||||
"allowFiles" => $this->config['imageAllowFiles']
|
"allowFiles" => $this->config['imageAllowFiles'],
|
||||||
);
|
);
|
||||||
$fieldName = $this->config['imageFieldName'];
|
$fieldName = $this->config['imageFieldName'];
|
||||||
$result = $this->uploadFile($config, $fieldName);
|
$result = $this->uploadFile($config, $fieldName);
|
||||||
@@ -43,7 +45,7 @@ class Ueditor{
|
|||||||
"pathFormat" => $this->config['scrawlPathFormat'],
|
"pathFormat" => $this->config['scrawlPathFormat'],
|
||||||
"maxSize" => $this->config['scrawlMaxSize'],
|
"maxSize" => $this->config['scrawlMaxSize'],
|
||||||
"allowFiles" => $this->config['scrawlAllowFiles'],
|
"allowFiles" => $this->config['scrawlAllowFiles'],
|
||||||
"oriName" => "scrawl.png"
|
"oriName" => "scrawl.png",
|
||||||
);
|
);
|
||||||
$fieldName = $this->config['scrawlFieldName'];
|
$fieldName = $this->config['scrawlFieldName'];
|
||||||
$result = $this->uploadBase64($config, $fieldName);
|
$result = $this->uploadBase64($config, $fieldName);
|
||||||
@@ -53,7 +55,7 @@ class Ueditor{
|
|||||||
$config = array(
|
$config = array(
|
||||||
"pathFormat" => $this->config['videoPathFormat'],
|
"pathFormat" => $this->config['videoPathFormat'],
|
||||||
"maxSize" => $this->config['videoMaxSize'],
|
"maxSize" => $this->config['videoMaxSize'],
|
||||||
"allowFiles" => $this->config['videoAllowFiles']
|
"allowFiles" => $this->config['videoAllowFiles'],
|
||||||
);
|
);
|
||||||
$fieldName = $this->config['videoFieldName'];
|
$fieldName = $this->config['videoFieldName'];
|
||||||
$result = $this->uploadFile($config, $fieldName);
|
$result = $this->uploadFile($config, $fieldName);
|
||||||
@@ -64,7 +66,7 @@ class Ueditor{
|
|||||||
$config = array(
|
$config = array(
|
||||||
"pathFormat" => $this->config['filePathFormat'],
|
"pathFormat" => $this->config['filePathFormat'],
|
||||||
"maxSize" => $this->config['fileMaxSize'],
|
"maxSize" => $this->config['fileMaxSize'],
|
||||||
"allowFiles" => $this->config['fileAllowFiles']
|
"allowFiles" => $this->config['fileAllowFiles'],
|
||||||
);
|
);
|
||||||
$fieldName = $this->config['fileFieldName'];
|
$fieldName = $this->config['fileFieldName'];
|
||||||
$result = $this->uploadFile($config, $fieldName);
|
$result = $this->uploadFile($config, $fieldName);
|
||||||
@@ -93,7 +95,7 @@ class Ueditor{
|
|||||||
"pathFormat" => $this->config['catcherPathFormat'],
|
"pathFormat" => $this->config['catcherPathFormat'],
|
||||||
"maxSize" => $this->config['catcherMaxSize'],
|
"maxSize" => $this->config['catcherMaxSize'],
|
||||||
"allowFiles" => $this->config['catcherAllowFiles'],
|
"allowFiles" => $this->config['catcherAllowFiles'],
|
||||||
"oriName" => "remote.png"
|
"oriName" => "remote.png",
|
||||||
);
|
);
|
||||||
$fieldName = $this->config['catcherFieldName'];
|
$fieldName = $this->config['catcherFieldName'];
|
||||||
$result = $this->saveRemote($config, $fieldName);
|
$result = $this->saveRemote($config, $fieldName);
|
||||||
@@ -101,7 +103,7 @@ class Ueditor{
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
$result = json_encode(array(
|
$result = json_encode(array(
|
||||||
'state'=> 'wrong require'
|
'state' => 'wrong require',
|
||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -112,7 +114,7 @@ class Ueditor{
|
|||||||
$this->output = htmlspecialchars($_GET["callback"]) . '(' . $result . ')';
|
$this->output = htmlspecialchars($_GET["callback"]) . '(' . $result . ')';
|
||||||
} else {
|
} else {
|
||||||
$this->output = json_encode(array(
|
$this->output = json_encode(array(
|
||||||
'state'=> 'callback参数不合法'
|
'state' => 'callback参数不合法',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -120,7 +122,6 @@ class Ueditor{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* 输出结果
|
* 输出结果
|
||||||
@@ -136,29 +137,26 @@ class Ueditor{
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private function uploadFile($config, $fieldName) {
|
private function uploadFile($config, $fieldName) {
|
||||||
|
$file = request()->file('upfile');
|
||||||
|
if (is_array($config['allowFiles'])) {
|
||||||
|
$config['allowFiles'] = str_replace('.', '', implode(',', $config['allowFiles']));
|
||||||
|
}else{
|
||||||
|
$config['allowFiles'] = '';
|
||||||
|
}
|
||||||
|
$info = $file->validate(array('size'=>$config['maxSize'], 'ext'=>$config['allowFiles']))->move($config['pathFormat'], true, false);
|
||||||
|
|
||||||
|
if ($info) {
|
||||||
$upload = new \org\Upload();
|
|
||||||
$upload->maxSize = $config['maxSize'] ;// 设置附件上传大小
|
|
||||||
$upload->exts = $this->format_exts($config['allowFiles']);// 设置附件上传类型
|
|
||||||
$upload->rootPath = '.'.$this->rootpath; // 设置附件上传根目录
|
|
||||||
$upload->autoSub = false;
|
|
||||||
$upload->savePath = $this->getFullPath($config['pathFormat']); // 设置附件上传(子)目录
|
|
||||||
$info=$upload->uploadOne($_FILES[$fieldName]);
|
|
||||||
$rootpath = $this->rootpath;
|
|
||||||
|
|
||||||
if(!$info){
|
|
||||||
$data = array(
|
$data = array(
|
||||||
"state"=>$upload -> getError(),
|
'state' => "SUCCESS",
|
||||||
|
'url' => str_replace("\\", '/', substr($info->getPathname(), 1)),
|
||||||
|
'title' => $info->getSaveName(),
|
||||||
|
'original' => $info->getFilename(),
|
||||||
|
'type' => '.' . $info->getExtension(),
|
||||||
|
'size' => $info->getSize(),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$data = array(
|
$data = array(
|
||||||
'state' => "SUCCESS",
|
"state" => $file->getError(),
|
||||||
'url' => $rootpath . $info['savepath'] . $info['savename'],
|
|
||||||
'title' => $info['name'],
|
|
||||||
'original' => $info['name'],
|
|
||||||
'type' => '.' . $info['ext'],
|
|
||||||
'size' => $info['size'],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return json_encode($data);
|
return json_encode($data);
|
||||||
@@ -223,7 +221,7 @@ class Ueditor{
|
|||||||
"state" => "no match file",
|
"state" => "no match file",
|
||||||
"list" => array(),
|
"list" => array(),
|
||||||
"start" => $start,
|
"start" => $start,
|
||||||
"total" => count($files)
|
"total" => count($files),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,7 +240,7 @@ class Ueditor{
|
|||||||
"state" => "SUCCESS",
|
"state" => "SUCCESS",
|
||||||
"list" => $list,
|
"list" => $list,
|
||||||
"start" => $start,
|
"start" => $start,
|
||||||
"total" => count($files)
|
"total" => count($files),
|
||||||
));
|
));
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
@@ -281,7 +279,7 @@ class Ueditor{
|
|||||||
ob_start();
|
ob_start();
|
||||||
$context = stream_context_create(
|
$context = stream_context_create(
|
||||||
array('http' => array(
|
array('http' => array(
|
||||||
'follow_location' => false // don't follow redirects
|
'follow_location' => false, // don't follow redirects
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
readfile($imgUrl, false, $context);
|
readfile($imgUrl, false, $context);
|
||||||
@@ -309,7 +307,7 @@ class Ueditor{
|
|||||||
"size" => strlen($img),
|
"size" => strlen($img),
|
||||||
"title" => $imgname,
|
"title" => $imgname,
|
||||||
"original" => $oriName,
|
"original" => $oriName,
|
||||||
"source" => htmlspecialchars($imgUrl)
|
"source" => htmlspecialchars($imgUrl),
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
array_push($list, array('state' => '文件写入失败'));
|
array_push($list, array('state' => '文件写入失败'));
|
||||||
@@ -319,7 +317,7 @@ class Ueditor{
|
|||||||
/* 返回抓取数据 */
|
/* 返回抓取数据 */
|
||||||
return json_encode(array(
|
return json_encode(array(
|
||||||
'state' => count($list) ? 'SUCCESS' : 'ERROR',
|
'state' => count($list) ? 'SUCCESS' : 'ERROR',
|
||||||
'list'=> $list
|
'list' => $list,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user