kindeditor远程图片本地化插件
实例为最新版本的kindeditor 4.1.5.
主要程序:
02 |
Const sFileExt= "jpg|gif|bmp|png" |
03 |
Function ReplaceRemoteUrl(sHTML, sSaveFilePath, sFileExt) |
06 |
If IsObjInstalled( "Microsof" & "t.X" & "MLHTTP" ) = False then |
07 |
ReplaceRemoteUrl = s_Content |
10 |
Dim re, RemoteFile, RemoteFileurl,SaveFileName,SaveFileType,arrSaveFileNameS,arrSaveFileName,sSaveFilePaths |
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) |
27 |
Response.write "" &RemoteFileurl& " 图片保存<font color='#FF0000'>失败</font>.<br />" |
30 |
ReplaceRemoteUrl = s_Content |
33 |
function SaveRemoteFile(s_LocalFileName,s_RemoteFileUrl) |
34 |
Dim Ads, Retrieval, GetRemoteData |
36 |
Set Retrieval = Server.CreateObject( "Microso" & "ft.XM" & "LHTTP" ) |
38 |
.Open "Get" , s_RemoteFileUrl, False , "" , "" |
40 |
GetRemoteData = .ResponseBody |
42 |
Set Retrieval = Nothing |
43 |
Set Ads = Server.CreateObject( "Ado" & "db.Str" & "eam" ) |
48 |
.SaveToFile Server.MapPath(s_LocalFileName), 2 |
54 |
SaveRemoteFile = false |
60 |
Function IsObjInstalled(s_ClassString) |
62 |
IsObjInstalled = False |
65 |
Set xTestObj = Server.CreateObject(s_ClassString) |
66 |
If 0 = Err Then IsObjInstalled = True |
67 |
Set xTestObj = Nothing |
在编辑框下加入代码:
<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