导航:首页 > 图片大全 > pubeditor如何上传图片

pubeditor如何上传图片

发布时间:2022-12-09 17:03:02

‘壹’ 如何实现编辑器在线图片文件上传功能

一般情况都是路径不对。

如果你使用的不是ueditor自带的上传类,那就就需要在调用页配置如下参数:

window.UEDITOR_HOME_URL='Public/ueditor1_3_6/';
window.onload=function(){
window.UEDITOR_CONFIG.imageUrl="/News/uploadimg"; //上传图片类路径。
window.UEDITOR_CONFIG.fileUrl="/News/uploadfile"; //上传文件类路径。
window.UEDITOR_CONFIG.videoPath="/News/uploadvideo"; //上传视频类路径。
window.UEDITOR_CONFIG.imagePath='upload/images/'; //修复返回图片路径。
window.UEDITOR_CONFIG.filePath='upload/txtfiles/'; //修复文件返回路径。
window.UEDITOR_CONFIG.videoPath='upload/video/'; //修复文件返回路径。
UE.getEditor('editor');
}

ueditor官方文档有很详细介绍的,以上配置在ueditor.config.js文件里面都能找到。

我现在在做的一个项目也是使用了这个编辑器,

使用方法都一样,自负的家伙!~( ^_^ )/~~拜拜!~~~~

‘贰’ 如何实现ckeditor文件上传

想把java web项目中的fckeditor在线文本编辑器升级到ckeditor,但又不想购买ckfinder来实现文件上传?老k将告诉你一个不用花钱就可以实现ckeditor上传文件的好方法,只要对fckeditor的filemanager做出几处修改,就可以集成fckeditor的文件上传管理器到ckeditor中使用,可以方便在文章中插入图片及flash。 1.在java web项目中集成fckeditor
如果你是把fckeditor升级到ckeditor的话,可以跳过这一步,否则请下载fckeditor的最终版本,然后把fckeditor文件夹复制到java web项目的webroot目录下。当然,你可以直接下载本文的示例项目fckeditro文件上传管理器集成到ckeditor示例项目 (0)来获得最终版本的fckeditor,而且是已经可以集成到ckeditor的fckeditor。 2.把java实现文件上传需要的jar复制到项目lib目录下
下载本文的示例项目后解压,把项目lib目录下的所有jar文件复制到你的项目的lib下面,如果不是通过myeclipse或者eclipse进行粘贴的话,你还需要把这些jar加入到项目编译路径下。
3.重写fckeditor实现文件上传的ConnectorServlet以解决中文乱码的问题
你可以直接到本文示例项目net.laokboke.servlet目录下的ConnectorServlet.java复制到你的项目的src目录下。
4.实现fckeditor的connector.userActionImpl
其实只需要把fckeditor.properties文件复制到你项目的src目录下就可以了 5.配置你的web.xml文件
配置上传文件的servlet,使tomcat启动的时候就加载该servlet,在web.xml中加入以下的代码:
<servlet>
<servlet-name>Connector</servlet-name> <servlet-class>
net.laokboke.servlet.ConnectorServlet
</servlet-class>

<init-param>
<param-name>baseDir</param-name> <param-value>/userfiles/</param-value> </init-param>
<init-param>
<param-name>debug</param-name> <param-value>true</param-value> </init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping> <servlet-name>Connector</servlet-name>
<url-pattern>/fckeditor/connector</url-pattern>

</servlet-mapping>
6.修改fckeditor文件上传管理器的若干文件
这些文件全部位于fckeditor\editor\filemanager\browser\default\目录下,你只需要把本文的示例项目中同目录下的所有文件复制替换你的就可以了。 7.修改ckeditor的图像属性窗口js,屏蔽一些不必要的选项
该文件是位于ckeditor\plugins\image\dialogs\目录下的image.js文件,增加了291-293这几行代码。
8.在ckeditor集成fckeditor filemanager
其实就是在使用ckeditor时配置它的filebrowserBrowseUrl和filebrowserUploadUrl等属性,如以下js代码
<script type="text/javascript"> CKEDITOR.replace( 'editor1', {
filebrowserBrowseUrl :
'<%=path %>/fckeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=/fckeditor/connector', filebrowserUploadUrl : '<%=path %>/fckeditor/connector?Type=Image'
}); </script>

‘叁’ 怎么为ckeditor添加图像

为ckeditor添加图像的方法
1. 到官网下载ckeditor
2. 复制到java web项目目录下
3. 配置config文件,打开图片上传功能

CKEDITOR.editorConfig = function (config) {
// 换行方式
config.enterMode = CKEDITOR.ENTER_BR;
// 当输入:shift+Enter是插入的标签
config.shiftEnterMode = CKEDITOR.ENTER_BR;//
//图片处理
config.pasteFromWordRemoveStyles = true;
config.filebrowserImageUploadUrl = "ckUploadImage.action?type=image";

// 去掉ckeditor“保存”按钮
config.removePlugins = 'save';
};

4. java后台处理代码
// 上传图片
@Action(value = "/ckUploadImage", results = { @Result(name = "success", location = "/upload.jsp") })
public String uploadImages() throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
FileOutputStream fos;
String webRoot = request.getSession().getServletContext().getRealPath(
"");
// 获取图片后缀名
String partRightType = uploadFileName.substring(uploadFileName
.lastIndexOf("."));
String CKEditorFuncNum = request.getParameter("CKEditorFuncNum");
// 判断图片的格式
if (!ImageFile.checkImageType(partRightType)) {
String path = "";
String alt_msg = "Sorry! Image format selection is incorrect, please choose GIF, jpeg, PNG format JPG, picture!";
pringWriterToPage("<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction("
+ CKEditorFuncNum
+ ", '"
+ path
+ "' , '"
+ alt_msg
+ "');</script>");
} else {
try {
uploadFileName = DateUtils.getDateNoStyle() + "-"
+ UUID.randomUUID() + partRightType;
String savePath = webRoot + Constants.UPLOAD_IMAGES_PATH;
File uploadFilePath = new File(savePath);
if (uploadFilePath.exists() == false) {
uploadFilePath.mkdirs();
System.out.println("路径不存在,但是已经成功创建了" + savePath);
} else {
System.out.println("路径存在了" + savePath);
}
fos = new FileOutputStream(new File(savePath + uploadFileName));
FileInputStream fis = new FileInputStream(getUpload());
byte[] buffer = new byte[1024];
int len = 0;
while ((len = fis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
fos.close();
fis.close();
} catch (FileNotFoundException foe) {
System.out.println("上传文件为0字节");
}
// String path = "http://" + request.getServerName() + ":"
// + request.getServerPort() + request.getContextPath()
// + Constants.UPLOAD_IMAGES_PATH + uploadFileName;
String path = request.getContextPath()
+ Constants.UPLOAD_IMAGES_PATH + uploadFileName;
String alt_msg = "";
pringWriterToPage("<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction("
+ CKEditorFuncNum
+ ", '"
+ path
+ "' , '"
+ alt_msg
+ "');</script>");
}
return null;
}

* 其实重点的代码就是这点
pringWriterToPage("<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction("
+ CKEditorFuncNum
+ ", '"
+ path
+ "' , '"
+ alt_msg
+ "');</script>");

‘肆’ htmleditor 如何上传图片

最近用Extjs做项目,用到htmleditor控件,唯一的缺陷是不可以上传图片,为了以后方便,在基于htmleditor控件上写了一个支持上传图片的。

控件StarHtmleditor

/**
* 重载EXTJS-HTML编辑器
*
* @class HTMLEditor
* @extends Ext.form.HtmlEditor
* @author wuliangbo
*/
HTMLEditor = Ext.extend(Ext.form.HtmlEditor, {
addImage : function() {
var editor = this;
var imgform = new Ext.FormPanel({
region : 'center',
labelWidth : 55,
frame : true,
bodyStyle : 'padding:5px 5px 0',
autoScroll : true,
border : false,
fileUpload : true,
items : [{
xtype : 'textfield',
fieldLabel : '选择文件',
name : 'userfile',
inputType : 'file',
allowBlank : false,
blankText : '文件不能为空',
height : 25,
anchor : '90%'
}],
buttons : [{
text : '上传',
type : 'submit',
handler : function() {
if (!imgform.form.isValid()) {return;}
imgform.form.submit({
waitMsg : '正在上传',
url : 'Default.aspx',
success : function(form, action) {
var element = document.createElement("img");
element.src = action.result.fileURL;
if (Ext.isIE) {
editor.insertAtCursor(element.outerHTML);
} else {
var selection = editor.win.getSelection();
if (!selection.isCollapsed) {
selection.deleteFromDocument();
}
selection.getRangeAt(0).insertNode(element);
}
win.hide();
},
failure : function(form, action) {
form.reset();
if (action.failureType == Ext.form.Action.SERVER_INVALID)
Ext.MessageBox.alert('警告',
action.result.errors.msg);
}
});
}
}, {
text : '关闭',
type : 'submit',
handler : function() {
win.close(this);
}
}]
})

var win = new Ext.Window({
title : "上传图片",
width : 300,
height : 200,
modal : true,
border : false,
iconCls : "picture.png",
layout : "fit",
items : imgform

});
win.show();
},
createToolbar : function(editor) {
HTMLEditor.superclass.createToolbar.call(this, editor);
this.tb.insertButton(16, {
cls : "x-btn-icon",
icon : "picture.png",
handler : this.addImage,
scope : this
});
}
});
Ext.reg('StarHtmleditor', HTMLEditor);

页面js代码

Ext.onReady(function() {
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';
var ff = new Ext.FormPanel({
title : "文件上传",
renderTo : document.body,
width : 600,
height : 480,
labelWidth : 55,
frame : true,
items : [{
xtype : "textfield",
name : "title",
fieldLabel : "标题",
anchor : "98%"
}, {
xtype : "combo",
name : "topic_id",
fieldLabel : "所属栏目",
anchor : "98%"
}, {
xtype : "textfield",
name : "keywords",
fieldLabel : "关键字",
anchor : "98%"
}, {
xtype : "StarHtmleditor",
name : "content",
fieldLabel : "内容",
anchor : "98%"
}]
});

});

后台代码简单实现了一下

protected void Page_Load(object sender, EventArgs e)
{
string fileName = string.Empty;
string fileURL = string.Empty;
string rt = string.Empty;
try
{
HttpPostedFile file = Request.Files[0];
fileName = GetFileName(file.FileName);
file.SaveAs(Server.MapPath("upload//") + fileName);
fileURL = "upload/" + fileName;
rt = "{success:'true',fileURL:'" + fileURL + "'}";
}
catch
{
rt = "{success:'false',fileURL:'" + fileURL + "'}";
}

Response.Write(rt);

}

private string GetFileName(string FullName)
{
string fileName = string.Empty;
int last = FullName.LastIndexOf(@"/");
fileName = FullName.Substring(last + 1, FullName.Length - last - 1);
return fileName;
}


实现效果如下

http://blog.csdn.net/zhaozhen1984/article/details/5911839

原文链接请查看谢谢。


http://www.cnblogs.com/wuliangbo/archive/2009/03/08/1406460.html

详查链接。谢谢。

阅读全文

与pubeditor如何上传图片相关的资料

热点内容
夹刘海发型图片 浏览:539
word图片浮雕效果 浏览:231
农村男生图片 浏览:323
梁字男生图片 浏览:511
被夸可爱了图片 浏览:99
浪琴男石英表价格图片 浏览:859
鸿蒙系统如何将图片扫描出来 浏览:223
微信图片怎么调整打印 浏览:344
油画棒简单漂亮的图片 浏览:128
九尾的图片高清 浏览:346
染发图片男生中分 浏览:230
高的繁体字怎么写图片 浏览:614
男生万圣节图片动漫 浏览:225
诞辰文字图片 浏览:653
美女屎图片大全 浏览:632
如何拆解摄像机图片 浏览:998
国庆卡通女孩图片 浏览:429
过耳短发发型图片 浏览:609
男生抽刀图片 浏览:320
耿姓氏图片文字 浏览:692