ueditor文本编辑器原本支持ctrl+v时复制文字和样式,由于ie协议的原因<input type='file' />必须必须点击,图片无法上传,本例是通过编写active控件解除限制向ftp上传,有更好的希望能告知,谢谢。
看很多小伙伴说不好使,其实不是不好使,是我编译的控件只支持xp,因为我是用xp编译调试的,这样把早期的c++源码也放出来,自己编译吧。
负责复制粘贴的ueditor文本编辑器js是ueditor1_2_6_1-src\_src\plugins\wordimage.js,改写其中UE.plugins["wordimage"] = function ()方法
//作者:牟云飞 //时间:2014年01月14日 //qq:1147417467 //active自定义粘贴图片 function uploadPasrseImage(src){ //alert("上传黏贴过来的图片"); //连接ftp var address = "***.**.**.**"; var port = "21"; var user = "**"; var pass = "*******"; var mode = "1"; var dir = "KMOCX";//这个名字的文件夹需要在ftp根目录中提前建立 var Ret = ToFtp.ConnectFtp(address,port,user,pass,mode); alert(src); image = src.substring(8,src.length); //上传的图片名 //取得当前时间 var now= new Date(); var year=now.getFullYear(); var month=now.getMonth()+1; var day=now.getDate(); var hour=now.getHours(); var minute=now.getMinutes(); var second=now.getSeconds(); var imageName=year+""+month+""+day+""+hour+""+minute+""+second+src.substring( src.lastIndexOf("."),src.length); dir =dir+"/"+year+""+month+""+day+""; //传图片第一个参数上传的文件路径,第二个上传服务器后的名字,第三个ftp根目录下的一个文件夹 var result=ToFtp.uploadToFtp(image, imageName,dir); alert(result); //上传服务器后的路径 image="ftp://"+user+":"+pass+"@"+address+"/"+dir+"/"+imageName; } //存放上传服务器后的路径 var image; UE.plugins["wordimage"] = function () { var me = this, images; me.addInputRule(function (root) { alert("-----"+image); utils.each(root.getNodesByTagName('img'), function (img) { var attrs = img.attrs, flag = parseInt(attrs.width) < 128 || parseInt(attrs.height) < 43, opt = me.options, src = opt.UEDITOR_HOME_URL + 'themes/default/images/spacer.gif'; //执行插件上传图片 if((attrs._src).indexOf("ftp")==-1){ //如果是粘贴操作,执行插件上传 uploadPasrseImage(attrs._src); alert("####"+image); //image=attrs._src; }else{ image=attrs._src; } if (attrs['_src'] && attrs['_src'].indexOf("file:///")!==-1) { img.setAttr({ width:attrs.width, height:attrs.height, alt:attrs.alt, word_img:"", src:image, _src:"", style:'background:url(' + ( flag ? opt.themePath + opt.theme + '/images/word.gif' : opt.langPath + opt.lang + '/images/localimage.png') + ') no-repeat center center;border:1px solid #ddd' }) } alert("执行完毕"); }) }); me.commands['wordimage'] = { execCommand:function () { images = domUtils.getElementsByTagName(me.document.body, "img"); var urlList = []; for (var i = 0, ci; ci = images[i++];) { var url = ci.getAttribute("word_img"); url && urlList.push(url); } if (images.length) { this["word_img"] = urlList; } }, queryCommandState:function () { images = domUtils.getElementsByTagName(me.document.body, "img"); for (var i = 0, ci; ci = images[i++];) { if (ci.getAttribute("word_img")) { return 1; } } return -1; } }; };
c++编写active时用的是如下方式上传ftp,本人现在做java, c++不是很好只能用这种方式了啊,c++的大神路过就好
m_pSesInternet = new CInternetSession;
m_pFtpCnt = m_pSesInternet->GetFtpConnection(Address, User, Pass, _wtoi(Port),bMode);
m_pFtpCnt->PutFile(LocalFile, FtpFile);
// UpToFtpCtrl.cpp : CUpToFtpCtrl ActiveX 控件类的实现。 #include "stdafx.h" #include "UpToFtp.h" #include "UpToFtpCtrl.h" #include "UpToFtpPropPage.h" #ifdef _DEBUG #define new DEBUG_NEW #endif IMPLEMENT_DYNCREATE(CUpToFtpCtrl, COleControl) // 消息映射 BEGIN_MESSAGE_MAP(CUpToFtpCtrl, COleControl) ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties) ON_WM_CREATE() END_MESSAGE_MAP() // 调度映射 BEGIN_DISPATCH_MAP(CUpToFtpCtrl, COleControl) DISP_FUNCTION_ID(CUpToFtpCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE) DISP_FUNCTION_ID(CUpToFtpCtrl, "ConnectFtp", dispidConnectFtp, ConnectFtp, VT_I4, VTS_BSTR VTS_BSTR VTS_BSTR VTS_BSTR VTS_BSTR) DISP_FUNCTION_ID(CUpToFtpCtrl, "WriteFtpFile", dispidWriteFtpFile, WriteFtpFile, VT_I4, VTS_BSTR VTS_BSTR) DISP_FUNCTION_ID(CUpToFtpCtrl, "writeToFtp", dispidwriteToFtp, writeToFtp, VT_BSTR, VTS_BSTR) DISP_FUNCTION_ID(CUpToFtpCtrl, "uploadToFtp", dispiduploadToFtp, uploadToFtp, VT_BSTR, VTS_BSTR VTS_BSTR VTS_BSTR) END_DISPATCH_MAP() // 事件映射 BEGIN_EVENT_MAP(CUpToFtpCtrl, COleControl) END_EVENT_MAP() // 属性页 // TODO: 按需要添加更多属性页。请记住增加计数! BEGIN_PROPPAGEIDS(CUpToFtpCtrl, 1) PROPPAGEID(CUpToFtpPropPage::guid) END_PROPPAGEIDS(CUpToFtpCtrl) // 初始化类工厂和 guid IMPLEMENT_OLECREATE_EX(CUpToFtpCtrl, "UPTOFTP.UpToFtpCtrl.1", 0xec5307a6, 0x6b48, 0x4614, 0xb3, 0x6, 0xd0, 0x1, 0x34, 0x53, 0x74, 0x25) // 键入库 ID 和版本 IMPLEMENT_OLETYPELIB(CUpToFtpCtrl, _tlid, _wVerMajor, _wVerMinor) // 接口 ID const IID BASED_CODE IID_DUpToFtp = { 0xCFC272C1, 0x21E3, 0x477D, { 0x8E, 0xDA, 0x3, 0x3F, 0x70, 0xC1, 0xD1, 0x49 } }; const IID BASED_CODE IID_DUpToFtpEvents = { 0xBFCA23EB, 0x98AC, 0x45C2, { 0x96, 0x3F, 0xAD, 0x19, 0xE9, 0x43, 0x48, 0xA7 } }; // 控件类型信息 static const DWORD BASED_CODE _dwUpToFtpOleMisc = OLEMISC_ACTIVATEWHENVISIBLE | OLEMISC_SETCLIENTSITEFIRST | OLEMISC_INSIDEOUT | OLEMISC_CANTLINKINSIDE | OLEMISC_RECOMPOSEONRESIZE; IMPLEMENT_OLECTLTYPE(CUpToFtpCtrl, IDS_UPTOFTP, _dwUpToFtpOleMisc) // CUpToFtpCtrl::CUpToFtpCtrlFactory::UpdateRegistry - // 添加或移除 CUpToFtpCtrl 的系统注册表项 BOOL CUpToFtpCtrl::CUpToFtpCtrlFactory::UpdateRegistry(BOOL bRegister) { // TODO: 验证您的控件是否符合单元模型线程处理规则。 // 有关更多信息,请参考 MFC 技术说明 64。 // 如果您的控件不符合单元模型规则,则 // 必须修改如下代码,将第六个参数从 // afxRegApartmentThreading 改为 0。 if (bRegister) return AfxOleRegisterControlClass( AfxGetInstanceHandle(), m_clsid, m_lpszProgID, IDS_UPTOFTP, IDB_UPTOFTP, afxRegApartmentThreading, _dwUpToFtpOleMisc, _tlid, _wVerMajor, _wVerMinor); else return AfxOleUnregisterClass(m_clsid, m_lpszProgID); } // CUpToFtpCtrl::CUpToFtpCtrl - 构造函数 CUpToFtpCtrl::CUpToFtpCtrl() { InitializeIIDs(&IID_DUpToFtp, &IID_DUpToFtpEvents); m_pSesInternet = NULL; } // CUpToFtpCtrl::~CUpToFtpCtrl - 析构函数 CUpToFtpCtrl::~CUpToFtpCtrl() { if(NULL != m_pSesInternet) delete m_pSesInternet; } // CUpToFtpCtrl::OnDraw - 绘图函数 void CUpToFtpCtrl::OnDraw( CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid) { if (!pdc) return; // TODO: 用您自己的绘图代码替换下面的代码。 pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH))); pdc->Ellipse(rcBounds); } // CUpToFtpCtrl::DoPropExchange - 持久性支持 void CUpToFtpCtrl::DoPropExchange(CPropExchange* pPX) { ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor)); COleControl::DoPropExchange(pPX); // TODO: 为每个持久的自定义属性调用 PX_ 函数。 } // CUpToFtpCtrl::OnResetState - 将控件重置为默认状态 void CUpToFtpCtrl::OnResetState() { COleControl::OnResetState(); // 重置 DoPropExchange 中找到的默认值 // TODO: 在此重置任意其他控件状态。 } // CUpToFtpCtrl::AboutBox - 向用户显示“关于”框 void CUpToFtpCtrl::AboutBox() { CDialog dlgAbout(IDD_ABOUTBOX_UPTOFTP); dlgAbout.DoModal(); } // CUpToFtpCtrl 消息处理程序 LONG CUpToFtpCtrl::ConnectFtp(LPCTSTR Address, LPCTSTR Port, LPCTSTR User, LPCTSTR Pass, LPCTSTR Mode) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); try { m_pSesInternet = new CInternetSession; BOOL bMode; if(0 == wcscmp(Mode, _T("1"))) bMode = TRUE; else bMode = FALSE; m_pFtpCnt = m_pSesInternet->GetFtpConnection(Address, User, Pass, _wtoi(Port),bMode); } catch (CInternetException *pEx) { TCHAR szMsg[MAX_PATH]; pEx->GetErrorMessage(szMsg, MAX_PATH); MessageBox(szMsg); return -1; } return 0; } LONG CUpToFtpCtrl::WriteFtpFile(LPCTSTR LocalFile, LPCTSTR FtpFile) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); return m_pFtpCnt->PutFile(LocalFile, FtpFile); } int CUpToFtpCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (COleControl::OnCreate(lpCreateStruct) == -1) return -1; CButton* pButton = new CButton(); pButton->Create(_T("我是一个按钮"), BS_BOTTOM, CRect(5, 5, 50, 20), this, 1001); pButton->ShowWindow(SW_SHOW); return 0; } BSTR CUpToFtpCtrl::writeToFtp(LPCTSTR imageurl) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CString strResult; // TODO: 在此添加调度处理程序代码 m_pFtpCnt->CreateDirectory(_T("testActive/TEST")); //设置当前目录 m_pFtpCnt->SetCurrentDirectory(_T("testActive/TEST")); //生成时间文件夹 time_t curTime= time(0); char tmp[64]; strftime( tmp, sizeof(tmp), "%Y/%m/%d",localtime(&curTime) ); CString dirName= CString(tmp); m_pFtpCnt->CreateDirectory(dirName); m_pFtpCnt->GetCurrentDirectoryW(strResult); m_pFtpCnt->PutFile(_T("C:\\aa.gif"),_T("aa.gif")); return strResult.AllocSysString(); } BSTR CUpToFtpCtrl::uploadToFtp(LPCTSTR localFile, LPCTSTR FtpFile, LPCTSTR ftpDir) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CString strResult; // TODO: 在此添加调度处理程序代码 //目录写法 testActive/TEST //设置目录 BOOL flag=m_pFtpCnt->SetCurrentDirectory(ftpDir); if(0==flag) { //如果目录不存在,则创建目录 m_pFtpCnt->CreateDirectory(ftpDir); m_pFtpCnt->SetCurrentDirectory(ftpDir); } m_pFtpCnt->SetCurrentDirectory(ftpDir); //上传图片 BOOL isSuccess= m_pFtpCnt->PutFile(localFile, FtpFile); if(1==isSuccess){ return _T("1"); }else{ return _T("2"); } }
完成控件之后,用regsvr32.exe 路径\**.ocx 注册一下控件
用ActiveX Control Pad编译控件
<OBJECT ID="ToFtp" WIDTH=0 HEIGHT=0
CLASSID="CLSID:EC5307A6-6B48-4614-B306-D00134537425">
<PARAM NAME="_Version" VALUE="65536">
<PARAM NAME="_ExtentX" VALUE="0">
<PARAM NAME="_ExtentY" VALUE="0">
<PARAM NAME="_StockProps" VALUE="0">
</OBJECT>放在使用ueditor的页面