当前位置:编程问答 > asp >

kindeditor远程图片本地化插件

实例为最新版本的kindeditor 4.1.5.

主要程序:

01 <%
02 Const sFileExt="jpg|gif|bmp|png"
03 Function ReplaceRemoteUrl(sHTML, sSaveFilePath, sFileExt)
04      Dim s_Content
05      s_Content = sHTML
06      If IsObjInstalled("Microsof" & "t.X" & "MLHTTP") = False then
07          ReplaceRemoteUrl = s_Content
08          Exit Function
09      End If    
10      Dim re, RemoteFile, RemoteFileurl,SaveFileName,SaveFileType,arrSaveFileNameS,arrSaveFileName,sSaveFilePaths
11      Set re = new RegExp
12      re.IgnoreCase = True
13      re.Global = True
14      re.Pattern = "((http|https|ftp|rtsp|mms):(\/\/|\\\\){1}((\w)+[.]){1,}(net|com|cn|org|cc|tv|[0-9]{1,3})(\S*\/)((\S)+[.]{1}(" & sFileExt & ")))"
15      Set RemoteFile = re.Execute(s_Content)
16      For Each RemoteFileurl in RemoteFile
17          arrSaveFileName = Split(RemoteFileurl,".")
18          SaveFileType=arrSaveFileName(UBound(arrSaveFileName))
19          RanNum=Int(900*Rnd)+100
20          arrSaveFileName = Year(Now()) & Right("0" & Month(Now()),2)&  Right("0" & Day(Now()),2) & Right("0" & Hour(Now()),2) & Right("0" & Minute(Now()),2) & Right("0" & Second(Now()),2) &ranNum&"."&SaveFileType
21   sSaveFilePaths= sSaveFilePath
22          SaveFileName = sSaveFilePaths & arrSaveFileName
23          if SaveRemoteFile(""&SaveFileName&"",""&RemoteFileurl&"") then
24          response.Write ""&SaveFileName&" 图片保存成功. <br />"
25          s_Content = Replace(s_Content,RemoteFileurl,SaveFileName)
26          else
27          Response.write ""&RemoteFileurl&" 图片保存<font color='#FF0000'>失败</font>.<br />"
28          end if
29      Next
30      ReplaceRemoteUrl = s_Content
31 End Function
32  
33 function SaveRemoteFile(s_LocalFileName,s_RemoteFileUrl)
34      Dim Ads, Retrieval, GetRemoteData
35      On Error Resume Next
36      Set Retrieval = Server.CreateObject("Microso" & "ft.XM" & "LHTTP")
37      With Retrieval
38          .Open "Get", s_RemoteFileUrl, False, "", ""
39          .Send
40          GetRemoteData = .ResponseBody
41      End With
42      Set Retrieval = Nothing
43      Set Ads = Server.CreateObject("Ado" & "db.Str" & "eam")
44      With Ads
45          .Type = 1
46          .Open
47          .Write GetRemoteData
48          .SaveToFile Server.MapPath(s_LocalFileName), 2
49          .Cancel()
50          .Close()
51      End With
52      Set Ads=nothing    
53      if err <> 0 then
54      SaveRemoteFile = false
55      err.clear
56      else
57      SaveRemoteFile = true
58      end if
59 End Function
60 Function IsObjInstalled(s_ClassString)
61      On Error Resume Next
62      IsObjInstalled = False
63      Err = 0
64      Dim xTestObj
65      Set xTestObj = Server.CreateObject(s_ClassString)
66      If 0 = Err Then IsObjInstalled = True
67      Set xTestObj = Nothing
68      Err = 0
69 End Function
70 %>

 

在编辑框下加入代码:

<input name="sSaveFileSelect" type="checkbox"  id="sSaveFileSelect" value="1">保存远程图片到本地

提交保存代码:

<%
sSaveFileSelect=request.Form("sSaveFileSelect")
sub_content=request.form("content")
if sSaveFileSelect=1 then
Set fso=Server.CreateObject("Scripting.FileSystemObject")
yy=right(year(date),4)
mm=right("00"&month(date),2)
dd=right("00"&day(date),2)
uploaddate=yy&mm&dd
uploadpath="../uploadfiles/image/"&uploaddate&"/"
If Not fso.FolderExists(Server.mappath(uploadpath)) Then
  fso.CreateFolder(Server.mappath(uploadpath))
End If
content=ReplaceRemoteUrl(sub_content,uploadpath,sFileExt)
else
content=sub_content
end if
%>

程序打包下载:结合kindeditor的远程图片保存插件.zip: http://www.zzzyk.com/upload/20139/7/20130907165637165.zip

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,