導航:首頁 > 圖片大全 > 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如何上傳圖片相關的資料

熱點內容
男生摸頭發笑動漫圖片 瀏覽:921
未成年宮野動漫圖片 瀏覽:762
怎麼擴大圖片儲存 瀏覽:804
小女孩疝氣的圖片大 瀏覽:284
如何錄照片加圖片 瀏覽:611
word粘貼圖片怎樣縮小 瀏覽:63
女生咬嘴唇圖片女孩 瀏覽:288
刮畫臉譜圖片大全 瀏覽:164
夾劉海發型圖片 瀏覽:541
word圖片浮雕效果 瀏覽:232
農村男生圖片 瀏覽:325
梁字男生圖片 瀏覽:513
被誇可愛了圖片 瀏覽:100
浪琴男石英錶價格圖片 瀏覽:861
鴻蒙系統如何將圖片掃描出來 瀏覽:225
微信圖片怎麼調整列印 瀏覽:346
油畫棒簡單漂亮的圖片 瀏覽:130
九尾的圖片高清 瀏覽:348
染發圖片男生中分 瀏覽:232
高的繁體字怎麼寫圖片 瀏覽:616