Ueditor.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\sys;
  12. use app\service\admin\upload\UploadService;
  13. use core\base\BaseAdminController;
  14. use think\Response;
  15. /**
  16. */
  17. class Ueditor extends BaseAdminController
  18. {
  19. public function getConfig() {
  20. return Response::create([
  21. "state" => "SUCCESS",
  22. "imageActionName" => "image",
  23. // 提交的图片表单名称,默认值:upfile
  24. "imageFieldName" => "file",
  25. // 上传大小限制,单位B,默认值:2048000
  26. "imageMaxSize" => 10485760,
  27. // 上传图片格式显示,默认值:[".png", ".jpg", ".jpeg", ".gif", ".bmp"]
  28. "imageAllowFiles" => [".jpg", ".png", ".jpeg"],
  29. // 是否压缩图片,默认是true
  30. "imageCompressEnable" => true,
  31. // 图片压缩最长边限制,默认值:1600
  32. "imageCompressBorder" => 5000,
  33. // 插入的图片浮动方式,默认值:none
  34. "imageInsertAlign" => "none",
  35. // 图片访问路径前缀,默认值:空
  36. "imageUrlPrefix" => url('/', domain: true)->buildUrl(),
  37. // 执行上传涂鸦的action名称,默认值:uploadscrawl
  38. "scrawlActionName" => "crawl",
  39. // 提交的图片表单名称,默认值:upfile
  40. "scrawlFieldName" => "file",
  41. // 上传大小限制,单位B,默认值:2048000
  42. "scrawlMaxSize" => 10485760,
  43. // 图片访问路径前缀,默认值:空
  44. "scrawlUrlPrefix" => "",
  45. // 插入的图片浮动方式,默认值:none
  46. "scrawlInsertAlign" => "none",
  47. // 执行上传截图的action名称,默认值:uploadimage
  48. "snapscreenActionName" => "snap",
  49. // 图片访问路径前缀
  50. "snapscreenUrlPrefix" => "",
  51. // 插入的图片浮动方式,默认值:none
  52. "snapscreenInsertAlign" => "none",
  53. // 例外的图片抓取域名
  54. "catcherLocalDomain" => array("127.0.0.1", "localhost"),
  55. // 执行抓取远程图片的action名称,默认值:catchimage
  56. "catcherActionName" => "catch",
  57. // 提交的图片列表表单名称,默认值:source
  58. "catcherFieldName" => "source",
  59. // 图片访问路径前缀,默认值:空
  60. "catcherUrlPrefix" => "",
  61. // 上传保存路径,可以自定义保存路径和文件名格式,默认值:{filename}{rand:6}
  62. "catcherMaxSize" => 10485760,
  63. // 抓取图片格式显示,默认值:[".png", ".jpg", ".jpeg", ".gif", ".bmp"]
  64. "catcherAllowFiles" => [".jpg", ".png", ".jpeg"],
  65. // 执行上传视频的action名称,默认值:uploadvideo
  66. "videoActionName" => "video",
  67. // 提交的视频表单名称,默认值:upfile
  68. "videoFieldName" => "file",
  69. // 视频访问路径前缀
  70. "videoUrlPrefix" => url('/', domain: true)->buildUrl(),
  71. // 上传大小限制,单位B,默认值:102400000
  72. "videoMaxSize" => 104857600,
  73. // 上传视频格式显示
  74. "videoAllowFiles" => [".mp4"],
  75. // 执行上传文件的action名称,默认值:uploadfile
  76. "fileActionName" => "file",
  77. // 提交的文件表单名称,默认值:upfile
  78. "fileFieldName" => "file",
  79. // 文件访问路径前缀
  80. "fileUrlPrefix" => "",
  81. // 上传保存路径,可以自定义保存路径和文件名格式,默认值:{filename}{rand:6}
  82. "fileMaxSize" => 104857600,
  83. // 上传文件格式显示
  84. "fileAllowFiles" => [".zip", ".pdf", ".doc"],
  85. // 执行图片管理的action名称,默认值:listimage
  86. "imageManagerActionName" => "listImage",
  87. // 每次列出文件数量
  88. "imageManagerListSize" => 20,
  89. // 图片访问路径前缀
  90. "imageManagerUrlPrefix" => "",
  91. // 插入的图片浮动方式,默认值:none
  92. "imageManagerInsertAlign" => "none",
  93. // 列出的文件类型
  94. "imageManagerAllowFiles" => [".jpg", ".png", ".jpeg"],
  95. // 执行文件管理的action名称,默认值:listfile
  96. "fileManagerActionName" => "listFile",
  97. // 指定要列出文件的目录
  98. "fileManagerUrlPrefix" => "",
  99. // 每次列出文件数量
  100. "fileManagerListSize" => 20,
  101. // 列出的文件类型
  102. "fileManagerAllowFiles" => [".zip", ".pdf", ".doc"],
  103. // 公式配置
  104. "formulaConfig" => [
  105. // 公式渲染的路径
  106. "imageUrlTemplate" => url('/', domain: true)->buildUrl() . "{}"
  107. ]
  108. ], 'json', 200);
  109. }
  110. public function upload() {
  111. $data = $this->request->params([
  112. ['action', ''],
  113. ['file', 'file'],
  114. ]);
  115. $upload_service = new UploadService();
  116. switch ($data['action']) {
  117. case 'image':
  118. $upload_res = $upload_service->image($data['file']);
  119. return Response::create([
  120. 'state' => 'SUCCESS',
  121. 'url' => $upload_res['url'],
  122. 'title' => $upload_res['url'],
  123. 'original' => $upload_res['url'],
  124. ], 'json', 200);
  125. break;
  126. case 'video':
  127. $upload_res = $upload_service->video($data['file']);
  128. return Response::create([
  129. 'state' => 'SUCCESS',
  130. 'url' => $upload_res['url'],
  131. 'title' => $upload_res['url'],
  132. 'original' => $upload_res['url'],
  133. ], 'json', 200);
  134. break;
  135. }
  136. }
  137. }