ueeditor无法上传图片_ueditor虚拟主机下图片上传失败,请重新上传

ueditor虚拟主机下图片上传失败,请重新上传

使用百度ueditor编辑器本地上传图片成功,使用ecs也不会出现此类的问题。将程序部署到虚拟主机下,上传图片提示“图片上传失败,请重新上传”。

出现此问题的原因是因为ueditor编辑器没有考虑到服务器的安全配置,但在绝大多数虚拟主机上,它都无法上传图片,这是一个坑爹的货。

在上传不了图片时,如果有你权限查看web访问日志,你可以看一个“拒绝访问”的错误。洪哥仔细调试分析,终于找到问题所在。

在它的upload.class.asp中,有如下一个函数:

Private Function CheckOrCreatePath( ByVal path )

Set fs = Server.CreateObject("Scripting.FileSystemObject")

Dim parts

parts = Split( path, "\" )

For Each part in parts

path = path + part + "\"

If fs.FolderExists( path ) = False Then

fs.CreateFolder( path )

End If

Next

End Function

将其修改如下:

Private Function CheckOrCreatePath( ByVal path )

Set fs = Server.CreateObject("Scripting.FileSystemObject")

Dim parts

Dim root : root = Server.mappath("/") & "\"

parts = Split( Replace(path, root, ""), "\" )

path = root

For Each part in parts

path = path + part + "\"

If fs.FolderExists( path ) = False Then

fs.CreateFolder( path )

End If

Next

End Function

上传的问题即可得到解决。

引起这个问题的主要原因是,大多数虚拟主机不会给IIS匿名账号访问磁盘上的非用户目录,连读取的权限都没有。

关于ueditor在虚拟主机中不能上传图片的问题,本文就介绍这么多,希望对您有所帮助,谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Spring中实现UEditor图片上传可以参考以下步骤: 1. 在前端Vue代码中配置UEditor富文本编辑器,并对上传图片做出相关设置。 2. 在Spring后端代码中编写图片上传的控制器,处理前端传递的图片文件信息。 3. 在Spring配置文件中配置文件上传的相关参数。 下面是具体的实现方法: 1. 前端代码: 在Vue组件中引入UEditor富文本编辑器,可以使用UEditor官网提供的Vue UEditor Wrapper组件。并在UEditor配置项中设置上传图片的相关参数,如下所示: ``` <template> <div> <vue-ueditor-wrap v-model="content" :config="ueditorConfig" :z-index="100" ></vue-ueditor-wrap> </div> </template> <script> import VueUeditorWrap from 'vue-ueditor-wrap'; export default { components: { VueUeditorWrap }, data () { return { content: '', ueditorConfig: { UEDITOR_HOME_URL: '/static/UEditor/', serverUrl: '/api/upload', maximumWords: 50000, initialFrameWidth: '100%', initialFrameHeight: 500, autoHeightEnabled: false, autoFloatEnabled: false, toolbars: [ ['source', 'bold', 'italic', 'underline', 'strikethrough', 'removeformat', 'formatmatch', 'forecolor', 'backcolor', 'fontfamily', 'fontsize', 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', 'touppercase', 'tolowercase', 'link', 'unlink', 'insertimage', 'emotion', 'scrawl', 'music', 'insertvideo', 'attachment', 'map', 'gmap', 'insertcode', 'template', 'background', 'date', 'time', 'spechars', 'searchreplace', 'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts' ] ] }, }; }, }; </script> ``` 在上述代码中,通过`serverUrl`参数设置了上传图片的后端接口地址为`/api/upload`。 2. 后端控制器代码: 在Spring中,可以通过编写一个控制器方法来实现UEditor上传图片的功能。具体代码如下: ``` @RequestMapping(value = "/api/upload", method = RequestMethod.POST) @ResponseBody public String uploadImage(HttpServletRequest request, HttpServletResponse response) throws Exception { request.setCharacterEncoding("utf-8"); response.setHeader("Content-Type", "text/html"); String rootPath = request.getSession().getServletContext().getRealPath("/"); String contextPath = request.getContextPath(); String basePath = rootPath + File.separator + "upload" + File.separator; String savePath = contextPath + "/upload/"; String[] fileType = {".gif", ".png", ".jpg", ".jpeg", ".bmp"}; String upfile = "upfile"; JSONObject result = new JSONObject(); MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; Iterator<String> iterator = multipartRequest.getFileNames(); while (iterator.hasNext()) { MultipartFile file = multipartRequest.getFile(iterator.next()); if (file != null) { String fileName = file.getOriginalFilename(); String fileExt = fileName.substring(fileName.lastIndexOf(".")).toLowerCase(); boolean isAllow = false; for (String ext : fileType) { if (ext.equals(fileExt)) { isAllow = true; break; } } if (!isAllow) { result.put("state", "不支持的文件类型!"); return result.toJSONString(); } String newFileName = UUID.randomUUID().toString() + fileExt; File uploadedFile = new File(basePath, newFileName); if (!uploadedFile.getParentFile().exists()) { uploadedFile.getParentFile().mkdirs(); } file.transferTo(uploadedFile); result.put("state", "SUCCESS"); result.put("url", savePath + newFileName); result.put("title", newFileName); result.put("original", fileName); result.put("type", fileExt); result.put("size", file.getSize()); } } return result.toJSONString(); } ``` 3. Spring配置文件: 在Spring的配置文件中,需要配置文件上传的相关参数。具体代码如下: ``` <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="10485760"/> <property name="defaultEncoding" value="UTF-8"/> <property name="resolveLazily" value="true"/> </bean> ``` 其中,`maxUploadSize`参数设置了上传文件的最大大小,单位为字节。 至此,我们就完成了在Spring+Vue中实现UEditor图片上传的方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值