编辑器图片上传问题

This commit is contained in:
2016-12-21 17:38:54 +08:00
parent 88c9a28681
commit 00b861e34f
2 changed files with 274 additions and 276 deletions
+8 -8
View File
@@ -9,7 +9,7 @@
"imageCompressBorder": 1600, /* */
"imageInsertAlign": "none", /* */
"imageUrlPrefix": "", /* 访 */
"imagePathFormat": "/ueditor/php/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* , */
"imagePathFormat": "./uploads/editor/image", /* , */
/* {filename} , */
/* {rand:6} , */
/* {time} */
@@ -26,14 +26,14 @@
/* 涂鸦图片上传配置项 */
"scrawlActionName": "uploadscrawl", /* 执行上传涂鸦的action名称 */
"scrawlFieldName": "upfile", /* 提交的图片表单名称 */
"scrawlPathFormat": "/ueditor/php/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
"scrawlPathFormat": "./uploads/editor/image", /* 上传保存路径,可以自定义保存路径和文件名格式 */
"scrawlMaxSize": 2048000, /* 上传大小限制,单位B */
"scrawlUrlPrefix": "", /* 图片访问路径前缀 */
"scrawlInsertAlign": "none",
/* 截图工具上传 */
"snapscreenActionName": "uploadimage", /* 执行上传截图的action名称 */
"snapscreenPathFormat": "/ueditor/php/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
"snapscreenPathFormat": "./uploads/editor/image", /* 上传保存路径,可以自定义保存路径和文件名格式 */
"snapscreenUrlPrefix": "", /* 图片访问路径前缀 */
"snapscreenInsertAlign": "none", /* 插入的图片浮动方式 */
@@ -41,7 +41,7 @@
"catcherLocalDomain": ["127.0.0.1", "localhost", "img.baidu.com"],
"catcherActionName": "catchimage", /* 执行抓取远程图片的action名称 */
"catcherFieldName": "source", /* 提交的图片列表表单名称 */
"catcherPathFormat": "/ueditor/php/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
"catcherPathFormat": "./uploads/editor/image", /* 上传保存路径,可以自定义保存路径和文件名格式 */
"catcherUrlPrefix": "", /* 图片访问路径前缀 */
"catcherMaxSize": 2048000, /* 上传大小限制,单位B */
"catcherAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 抓取图片格式显示 */
@@ -49,7 +49,7 @@
/* 上传视频配置 */
"videoActionName": "uploadvideo", /* 执行上传视频的action名称 */
"videoFieldName": "upfile", /* 提交的视频表单名称 */
"videoPathFormat": "/ueditor/php/upload/video/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
"videoPathFormat": "./uploads/editor/video", /* 上传保存路径,可以自定义保存路径和文件名格式 */
"videoUrlPrefix": "", /* 视频访问路径前缀 */
"videoMaxSize": 102400000, /* 上传大小限制,单位B,默认100MB */
"videoAllowFiles": [
@@ -59,7 +59,7 @@
/* 上传文件配置 */
"fileActionName": "uploadfile", /* controller里,执行上传视频的action名称 */
"fileFieldName": "upfile", /* 提交的文件表单名称 */
"filePathFormat": "/ueditor/php/upload/file/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
"filePathFormat": "./uploads/editor/file", /* 上传保存路径,可以自定义保存路径和文件名格式 */
"fileUrlPrefix": "", /* 文件访问路径前缀 */
"fileMaxSize": 51200000, /* 上传大小限制,单位B,默认50MB */
"fileAllowFiles": [
@@ -72,7 +72,7 @@
/* 列出指定目录下的图片 */
"imageManagerActionName": "listimage", /* 执行图片管理的action名称 */
"imageManagerListPath": "/ueditor/php/upload/image/", /* 指定要列出图片的目录 */
"imageManagerListPath": "./uploads/editor/image/", /* 指定要列出图片的目录 */
"imageManagerListSize": 20, /* 每次列出文件数量 */
"imageManagerUrlPrefix": "", /* 图片访问路径前缀 */
"imageManagerInsertAlign": "none", /* 插入的图片浮动方式 */
@@ -80,7 +80,7 @@
/* 列出指定目录下的文件 */
"fileManagerActionName": "listfile", /* 执行文件管理的action名称 */
"fileManagerListPath": "/ueditor/php/upload/file/", /* 指定要列出文件的目录 */
"fileManagerListPath": "./uploads/editor/file/", /* 指定要列出文件的目录 */
"fileManagerUrlPrefix": "", /* 文件访问路径前缀 */
"fileManagerListSize": 20, /* 每次列出文件数量 */
"fileManagerAllowFiles": [
+30 -32
View File
@@ -16,7 +16,9 @@ class Ueditor{
public function __construct($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);
@@ -32,7 +34,7 @@ class Ueditor{
$config = array(
"pathFormat" => $this->config['imagePathFormat'],
"maxSize" => $this->config['imageMaxSize'],
"allowFiles" => $this->config['imageAllowFiles']
"allowFiles" => $this->config['imageAllowFiles'],
);
$fieldName = $this->config['imageFieldName'];
$result = $this->uploadFile($config, $fieldName);
@@ -43,7 +45,7 @@ class Ueditor{
"pathFormat" => $this->config['scrawlPathFormat'],
"maxSize" => $this->config['scrawlMaxSize'],
"allowFiles" => $this->config['scrawlAllowFiles'],
"oriName" => "scrawl.png"
"oriName" => "scrawl.png",
);
$fieldName = $this->config['scrawlFieldName'];
$result = $this->uploadBase64($config, $fieldName);
@@ -53,7 +55,7 @@ class Ueditor{
$config = array(
"pathFormat" => $this->config['videoPathFormat'],
"maxSize" => $this->config['videoMaxSize'],
"allowFiles" => $this->config['videoAllowFiles']
"allowFiles" => $this->config['videoAllowFiles'],
);
$fieldName = $this->config['videoFieldName'];
$result = $this->uploadFile($config, $fieldName);
@@ -64,7 +66,7 @@ class Ueditor{
$config = array(
"pathFormat" => $this->config['filePathFormat'],
"maxSize" => $this->config['fileMaxSize'],
"allowFiles" => $this->config['fileAllowFiles']
"allowFiles" => $this->config['fileAllowFiles'],
);
$fieldName = $this->config['fileFieldName'];
$result = $this->uploadFile($config, $fieldName);
@@ -93,7 +95,7 @@ class Ueditor{
"pathFormat" => $this->config['catcherPathFormat'],
"maxSize" => $this->config['catcherMaxSize'],
"allowFiles" => $this->config['catcherAllowFiles'],
"oriName" => "remote.png"
"oriName" => "remote.png",
);
$fieldName = $this->config['catcherFieldName'];
$result = $this->saveRemote($config, $fieldName);
@@ -101,7 +103,7 @@ class Ueditor{
default:
$result = json_encode(array(
'state'=> 'wrong require'
'state' => 'wrong require',
));
break;
@@ -112,7 +114,7 @@ class Ueditor{
$this->output = htmlspecialchars($_GET["callback"]) . '(' . $result . ')';
} else {
$this->output = json_encode(array(
'state'=> 'callback参数不合法'
'state' => 'callback参数不合法',
));
}
} else {
@@ -120,7 +122,6 @@ class Ueditor{
}
}
/**
*
* 输出结果
@@ -136,29 +137,26 @@ class Ueditor{
*
*/
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);
$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){
if ($info) {
$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 {
$data = array(
'state' => "SUCCESS",
'url' => $rootpath . $info['savepath'] . $info['savename'],
'title' => $info['name'],
'original' => $info['name'],
'type' => '.' . $info['ext'],
'size' => $info['size'],
"state" => $file->getError(),
);
}
return json_encode($data);
@@ -223,7 +221,7 @@ class Ueditor{
"state" => "no match file",
"list" => array(),
"start" => $start,
"total" => count($files)
"total" => count($files),
));
}
@@ -242,7 +240,7 @@ class Ueditor{
"state" => "SUCCESS",
"list" => $list,
"start" => $start,
"total" => count($files)
"total" => count($files),
));
return $result;
@@ -281,7 +279,7 @@ class Ueditor{
ob_start();
$context = stream_context_create(
array('http' => array(
'follow_location' => false // don't follow redirects
'follow_location' => false, // don't follow redirects
))
);
readfile($imgUrl, false, $context);
@@ -309,7 +307,7 @@ class Ueditor{
"size" => strlen($img),
"title" => $imgname,
"original" => $oriName,
"source" => htmlspecialchars($imgUrl)
"source" => htmlspecialchars($imgUrl),
));
} else {
array_push($list, array('state' => '文件写入失败'));
@@ -319,7 +317,7 @@ class Ueditor{
/* 返回抓取数据 */
return json_encode(array(
'state' => count($list) ? 'SUCCESS' : 'ERROR',
'list'=> $list
'list' => $list,
));
}