Hl.WebMain/Source/jsplug/jq.xheditor/demos/saveremoteimg.asp

(开头部分) 4KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<%@ codepage=65001%><%
' saveremoteimg demo for asp
' @requires xhEditor
' 
' @author Yanis.Wang<yanis.wang@gmail.com>
' @site http://xheditor.com/
' @licence LGPL(http://www.opensource.org/licenses/lgpl-license.php)
' 
' @Version: 0.9.1 (build 110703)
'
' 注:本程序仅为演示用,只实现了最简单的远程抓图及粘贴上传,如果要完善此功能,还需要自行开发以下功能:
'		1,非图片扩展名的URL地址抓取
'		2,大体积的图片转jpg格式,以及加水印等后续操作
'		3,上传记录存入数据库以管理用户上传图片
'
'option explicit

response.charset="UTF-8"

	dim attachDir,dirType,maxAttachSize,upExt
	attachDir="upload"'上传文件保存路径,结尾不要带/
	dirType=1'1:按天存入目录 2:按月存入目录 3:按扩展名存目录  建议使用按天存
	maxAttachSize=2097152'最大上传大小,默认是2M
	upExt="jpg,jpeg,gif,png"'上传扩展名

	'------------------------------------------------------------
	
	upExt=","&upExt&","
	dim arrUrl,i,localUrl,filesize
	arrUrl=split(request("urls"),"|")
	for i=0 to Ubound(arrUrl)
		localUrl=saveRemoteImg(arrUrl(i))
		if localUrl<>"" then arrUrl(i)=localUrl
	next
	response.write Join(arrUrl,"|")
	response.end
	
	
	'保存远程文件
	Function saveRemoteImg(sUrl)
		dim fileContent,objStream,sExt,sFile
		if left(sUrl,10)="data:image" then'base64编码的图片,可能出现在firefox粘贴,或者某些网站上,例如google图片
			dim pstart
			pstart=instr(sUrl,"/")+1
			sExt=LCase(mid(sUrl,pstart,instr(sUrl,";")-pstart))
			if not cbool(InStr(1,upExt,","&sExt&",")) then exit function
			fileContent=DecodeBase64(mid(sUrl,instr(sUrl,"base64,")+7))
		else
			sExt=LCase(Mid(sUrl,InStrRev(sUrl, ".")+1))
			if not cbool(InStr(1,upExt,","&sExt&",")) then exit function
			fileContent=getUrl(sUrl)
		end if
		if LenB(fileContent)>maxAttachSize then exit function'文件体积超过最大限制
		sFile=getLocalPath(sExt)
		Set objStream = Server.CreateObject("ADODB.Stream")
		objStream.Type =1
		objStream.Open
		objstream.write fileContent
		objstream.SaveToFile server.mappath(sFile),2
		objstream.Close()
后面还有 83 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。