提交 66b952ec 编写于 作者: E eddy8

add: catch remote image

上级 2ad52fba
......@@ -71,6 +71,32 @@ class NEditorController extends Controller
];
}
public function catchImage(Request $request)
{
if (config('light.image_upload.driver') !== 'local') {
$class = config('light.image_upload.class');
return call_user_func([new $class, 'catchImage'], $request);
}
$files = (array) $request->post('file');
$urls = [];
foreach ($files as $v) {
$extention = pathinfo(parse_url($v, PHP_URL_PATH), PATHINFO_EXTENSION);
$path = date('Ym') . '/' . md5($v) . '.' . ($extention == '' ? 'jpg' : $extention);
Storage::disk(config('light.neditor.disk'))
->put($path, file_get_contents($v));
$urls[] = [
'url' => Storage::disk(config('light.neditor.disk'))->url($path),
'source' => $v,
'state' => 'SUCCESS'
];
}
return [
'list' => $urls
];
}
protected function isValidImage(UploadedFile $file)
{
if (!$file->isValid() ||
......
......@@ -40,7 +40,16 @@
scrawlUrlPrefix: "",
videoUrlPrefix: "",
fileUrlPrefix: "",
catcherLocalDomain: "",
/* 抓取远程图片配置 */
catcherLocalDomain : ["127.0.0.1", "localhost", "img.baidu.com"],
catcherActionName : "catchimage", /* 执行抓取远程图片的action名称 */
catcherFieldName : "file", /* 提交的图片列表表单名称 */
catcherPathFormat : "/ueditor/php/upload/image/{yyyy}{mm}{dd}/{time}{rand =>6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
catcherUrlPrefix : "", /* 图片访问路径前缀 */
catcherMaxSize : 2048000, /* 上传大小限制,单位B */
catcherAllowFiles : [".png", ".jpg", ".jpeg", ".gif", ".bmp", ".webp"], /* 抓取图片格式显示 */
//工具栏上的所有的功能按钮和下拉框,可以在new编辑器的实例时选择自己需要的重新定义
toolbars: [
[
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册