kindeditor编辑器远程图片本地化ASP插件-实例版本的kindeditor 4.1.5,请自行参考。 Const sFileExt = jpg|gif|bmp|png ...

海南网站建设,网页设计
记忆工作中的点滴
首页>> Asp技术 >>kindeditor编辑器远程图片本地化ASP插件

实例版本的kindeditor 4.1.5,请自行参考。

Const sFileExt = "jpg|gif|bmp|png"
Function ReplaceRemoteUrl(sHTML, sSaveFilePath, sFileExt)
	Dim s_Content
	s_Content = sHTML
	If IsObjInstalled("Microsof" & "t.X" & "MLHTTP") = False Then
		ReplaceRemoteUrl = s_Content
		Exit Function
	End If
	Dim re
	Dim RemoteFile
	Dim RemoteFileurl
	Dim SaveFileName
	Dim SaveFileType
	Dim arrSaveFileNameS
	Dim arrSaveFileName
	Dim sSaveFilePaths
	Set re = new RegExp
	re.IgnoreCase = True
	re.Global = True
	re.Pattern = "((http|https|ftp|rtsp|mms):(\/\/|\\\\){1}((\w)+[.]){1,}(net|com|cn|org|cc|tv|[0-9]{1,3})(\S*\/)((\S)+[.]{1}(" & sFileExt & ")))"
	Set RemoteFile = re.Execute(s_Content)
	For Each RemoteFileurl in RemoteFile
		arrSaveFileName = Split(RemoteFileurl,".")
		SaveFileType = arrSaveFileName(UBound(arrSaveFileName))
		RanNum = Int(900*Rnd) + 100
		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
		sSaveFilePaths = sSaveFilePath
		SaveFileName = sSaveFilePaths & arrSaveFileName
		If SaveRemoteFile("" & SaveFileName & "","" & RemoteFileurl & "") Then
			Response.Write "" & SaveFileName & " 图片保存成功. <br />"
			s_Content = Replace(s_Content,RemoteFileurl,SaveFileName)
		Else
			Response.Write "" & RemoteFileurl & " 图片保存<font color='#FF0000'>失败</font>.<br />"
		End If
	Next
	ReplaceRemoteUrl = s_Content
End Function

Function SaveRemoteFile(s_LocalFileName,s_RemoteFileUrl)
	Dim Ads
	Dim Retrieval
	Dim GetRemoteData
	On Error Resume Next
	Set Retrieval = Server.CreateObject("Microso" & "ft.XM" & "LHTTP")
	With Retrieval
		.Open "Get", s_RemoteFileUrl, False, "", ""
		.Send
		GetRemoteData = .ResponseBody
	End With
	Set Retrieval = Nothing
	Set Ads = Server.CreateObject("Ado" & "db.Str" & "eam")
	With Ads
		.Type = 1
		.Open
		.Write GetRemoteData
		.SaveToFile Server.MapPath(s_LocalFileName), 2
		.Cancel()
		.Close()
	End With
	Set Ads = Nothing
	If Err <> 0 Then
		SaveRemoteFile = False
		Err.Clear
	Else
		SaveRemoteFile = True
	End If
End Function

Function IsObjInstalled(s_ClassString)
	On Error Resume Next
	IsObjInstalled = False
	Err = 0
	Dim xTestObj
	Set xTestObj = Server.CreateObject(s_ClassString)
	If 0 = Err Then IsObjInstalled = True
	Set xTestObj = Nothing
	Err = 0
End Function

在编辑框文件中加入以下代码:

<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 = "../uploads/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编辑器远程图片本地化ASP插件
标签: 编辑器 kindeditor 远程图片本地化

发表评论

路人甲 表情
看不清楚?点图切换 Ctrl+Enter快速提交

网友评论(0)