主题: kindeditor3.3.1(ASP修改版) |
作者: mango, 发布日期: 2009-11-07 21:28:26, 浏览数: 8770 |
编辑器原来的PHP文件夹改为asp文件夹,文件夹里有upload.asp和upload.inc两个文件 upload代码如下: <!--#include file="upload.inc" --> <%call uploadfile()%> <% function uploadfile() set UploadObj=new upload_mango id=replace(trim(UploadObj.form("id")),"'","") imgTitle=replace(trim(UploadObj.form("imgTitle")),"'","") imgWidth=replace(trim(UploadObj.form("imgWidth")),"'","") imgHeight=replace(trim(UploadObj.form("imgHeight")),"'","") imgBorder=replace(trim(UploadObj.form("imgBorder")),"'","") set FileObj = UploadObj.file("imgFile") if FileObj.filename<>"" then fileExt=lcase(right(FileObj.filename,4)) if fileExt<>".gif" and fileExt<>".jpg" and fileExt<>".JPG" and fileExt<>".GIF" and fileExt<>".bmp" and fileExt<>".BMP" and fileExt<>".png" and fileExt<>".PNG" then response.write("<script language=javascript>alert('文件格式不正确,请上传jpg或gif格式的图片!');location='"&request.servervariables("http_referer")&"'</script>") response.end end if if FileObj.filesize>0 then randomize ranNum=int(900*rnd)+100 formpath="../../Upload/" filename=makefilename(now())&ranNum&"."& GetExtendName(FileObj.filename) FileObj.saveas server.mappath(formpath&filename) '保存文件 set FileObj=nothing set upload=nothing savefilename=formpath&filename %> <html> <head> <title>Insert Image</title> <meta http-equiv="content-type" content="text/html; charset=gb2312"> </head> <body> <script language="Javascript"> parent.KE.plugin["image"].insert("<%=id%>", "<%=savefilename%>","<%=imgTitle%>","<%=imgWidth%>","<%=imgHeight%>","<%=imgBorder%>"); </script> </body> </html> <% end if end if end function %> <%'为文件命名 Function makefilename(filename) filename=replace(filename,"-","") filename=replace(filename," ","") filename=replace(filename,":","") filename=replace(filename,"pm","") filename=replace(filename,"am","") filename=replace(filename,"上午","") filename=replace(filename,"下午","") makefilename=filename End Function %> <%'取得文件类型 Function GetExtendName(filename) dim ExtName ExtName=lcase(filename) ExtName=right(ExtName,3) ExtName=right(ExtName,3-instr(ExtName,".")) GetExtendName=ExtName End Function %> upload.inc代码如下: <SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT> dim Data_mango Class upload_mango dim objForm,objFile,Version Public function Form(strForm) strForm=lcase(strForm) if not objForm.exists(strForm) then Form="" else Form=objForm(strForm) end if end function Public function File(strFile) strFile=lcase(strFile) if not objFile.exists(strFile) then set File=new FileInfo else set File=objFile(strFile) end if end function Private Sub Class_Initialize dim RequestData,sStart,vbCrlf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,theFile dim iFileSize,sFilePath,sFileType,sFormValue,sFileName dim iFindStart,iFindEnd dim iFormStart,iFormEnd,sFormName Version="化境HTTP上传程序 Version 2.0" set objForm=Server.CreateObject("Scripting.Dictionary") set objFile=Server.CreateObject("Scripting.Dictionary") if Request.TotalBytes<1 then Exit Sub set tStream = Server.CreateObject("adodb.stream") set Data_mango = Server.CreateObject("adodb.stream") Data_mango.Type = 1 Data_mango.Mode =3 Data_mango.Open Data_mango.Write Request.BinaryRead(Request.TotalBytes) Data_mango.Position=0 RequestData =Data_mango.Read iFormStart = 1 iFormEnd = LenB(RequestData) vbCrlf = chrB(13) & chrB(10) sStart = MidB(RequestData,1, InStrB(iFormStart,RequestData,vbCrlf)-1) iStart = LenB (sStart) iFormStart=iFormStart+iStart+1 while (iFormStart + 10) < iFormEnd iInfoEnd = InStrB(iFormStart,RequestData,vbCrlf & vbCrlf)+3 tStream.Type = 1 tStream.Mode =3 tStream.Open Data_mango.Position = iFormStart Data_mango.CopyTo tStream,iInfoEnd-iFormStart tStream.Position = 0 tStream.Type = 2 tStream.Charset ="gb2312" sInfo = tStream.ReadText tStream.Close '取得表单项目名称 iFormStart = InStrB(iInfoEnd,RequestData,sStart) iFindStart = InStr(22,sInfo,"name=""",1)+6 iFindEnd = InStr(iFindStart,sInfo,"""",1) sFormName = lcase(Mid (sinfo,iFindStart,iFindEnd-iFindStart)) '如果是文件 if InStr (45,sInfo,"filename=""",1) > 0 then set theFile=new FileInfo '取得文件名 iFindStart = InStr(iFindEnd,sInfo,"filename=""",1)+10 iFindEnd = InStr(iFindStart,sInfo,"""",1) sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart) theFile.FileName=getFileName(sFileName) theFile.FilePath=getFilePath(sFileName) '取得文件类型 iFindStart = InStr(iFindEnd,sInfo,"Content-Type: ",1)+14 iFindEnd = InStr(iFindStart,sInfo,vbCr) theFile.FileType =Mid (sinfo,iFindStart,iFindEnd-iFindStart) theFile.FileStart =iInfoEnd theFile.FileSize = iFormStart -iInfoEnd -3 theFile.FormName=sFormName if not objFile.Exists(sFormName) then objFile.add sFormName,theFile end if else '如果是表单项目 tStream.Type =1 tStream.Mode =3 tStream.Open Data_mango.Position = iInfoEnd Data_mango.CopyTo tStream,iFormStart-iInfoEnd-3 tStream.Position = 0 tStream.Type = 2 tStream.Charset ="gb2312" sFormValue = tStream.ReadText tStream.Close if objForm.Exists(sFormName) then objForm(sFormName)=objForm(sFormName)&", "&sFormValue else objForm.Add sFormName,sFormValue end if end if iFormStart=iFormStart+iStart+1 wend RequestData="" set tStream =nothing End Sub Private Sub Class_Terminate if Request.TotalBytes>0 then objForm.RemoveAll objFile.RemoveAll set objForm=nothing set objFile=nothing Data_mango.Close set Data_mango =nothing end if End Sub Private function GetFilePath(FullPath) If FullPath <> "" Then GetFilePath = left(FullPath,InStrRev(FullPath, "\")) Else GetFilePath = "" End If End function Private function GetFileName(FullPath) If FullPath <> "" Then GetFileName = mid(FullPath,InStrRev(FullPath, "\")+1) Else GetFileName = "" End If End function End Class Class FileInfo dim FormName,FileName,FilePath,FileSize,FileType,FileStart Private Sub Class_Initialize FileName = "" FilePath = "" FileSize = 0 FileStart= 0 FormName = "" FileType = "" End Sub Public function SaveAs(FullPath) dim dr,ErrorChar,i SaveAs=true if trim(fullpath)="" or FileStart=0 or FileName="" or right(fullpath,1)="/" then exit function set dr=CreateObject("Adodb.Stream") dr.Mode=3 dr.Type=1 dr.Open Data_mango.position=FileStart Data_mango.copyto dr,FileSize dr.SaveToFile FullPath,2 dr.Close set dr=nothing SaveAs=false end function End Class </SCRIPT> 把plugins文件夹下面的image.html改为如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 默认本地上传图片的路径是网站根目录下面的Upload文件夹,路径更改可以改upload.asp里的 formpath="../../Upload/" filename=makefilename(now())&ranNum&"."& GetExtendName(FileObj.filename) FileObj.saveas server.mappath(formpath&filename) '保存文件 set FileObj=nothing set upload=nothing savefilename=formpath&filename |