Home>

asp replaces and saves remote pictures through functions,Complete the function of automatically collecting pictures and extracting pictures,Automatically determine duplicate pictures in the function,Intelligently analyze link paths,And convert it into a relative image address and save it in the website directory you specified.We can use this function in a background editor,When you copy content that contains pictures,This code will help you upload pictures automatically.At the same time, this code is also an important processing function in the acquisition program.The function code is as follows:

function replacesaveremotefile (constr, strinstalldir, strchanneldir, savetf, tisturl)
if constr="$false $" or constr="" or strinstalldir="" or strchanneldir="" then
replacesaveremotefile=constr
exit function
end if
dim tempstr, tempstr2, tempstr3, re, matches, match, tempi, temparray, temparray2
set re=new regexp
re.ignorecase=true
re.global=true
re.pattern="]>"
set matches=re.execute (constr)
for each match in matches
if tempstr<>"" then
tempstr=tempstr&"$array $"&match.value
else
tempstr=match.value
end if
next
if tempstr<>"" then
temparray=split (tempstr, "$array $")
tempstr=""
for tempi=0 to ubound (temparray)
re.pattern="src \ s *=\ s *. +?\. (gif | jpg | bmp | jpeg | psd | png | svg | dxf | wmf | tiff)"
set matches=re.execute (temparray (tempi))
for each match in matches
if tempstr<>"" then
tempstr=tempstr&"$array $"&match.value
else
tempstr=match.value
end if
next
next
end if
if tempstr<>"" then
re.pattern="src \ s *=\ s *"
tempstr=re.replace (tempstr, "")
end if
set matches=nothing
set re=nothing
if tempstr="" or isnull (tempstr)=true then
replacesaveremotefile=constr
exit function
end if
tempstr=replace (tempstr, "" "", "")
tempstr=replace (tempstr, "" "," ")
tempstr=replace (tempstr, "", "")
dim remotefileurl, savepath, pathtemp, dtnow, strfilename, strfiletype, arrsavefilename, rannum, arr_path
dtnow=now ()
if savetf=true then
savepath=strchanneldir&"/"&year (dtnow)&right ("0"&​​month (dtnow), 2)&"/"
  response.write "link path:"&savepath&""
arr_path=split (savepath, "/")
pathtemp=""
for tempi=0 to ubound (arr_path)
if tempi=0 then
pathtemp=arr_path (0)&"/"
elseif tempi=ubound (arr_path) then
exit for
else
pathtemp=pathtemp&arr_path (tempi)&"/"
end if
if checkdir (pathtemp)=false then
if makenewsdir (pathtemp)=false then
savetf=false
exit for
end if
end if
next
end if
"Remove duplicate pictures
temparray=split (tempstr, "$array $")
tempstr=""
for tempi=0 to ubound (temparray)
if instr (lcase (tempstr), lcase (temparray (tempi)))<1 then
tempstr=tempstr&"$array $"&temparray (tempi)
end if
next
tempstr=right (tempstr, len (tempstr) -7)
temparray=split (tempstr, "$array $")
"Convert Relative Picture Address
tempstr=""
for tempi=0 to ubound (temparray)
tempstr=tempstr&"$array $"&definiteurl (temparray (tempi), tisturl)
next
tempstr=right (tempstr, len (tempstr) -7)
tempstr=replace (tempstr, chr (0), "")
temparray2=split (tempstr, "$array $")
tempstr=""
"Picture replacement/save
set re=new regexp
re.ignorecase=true
re.global=true
for tempi=0 to ubound (temparray2)
remotefileurl=temparray2 (tempi)
if remotefileurl<>"$false $" and savetf=true then "
arrsavefilename=split (remotefileurl, ".")
  strfiletype=lcase (arrsavefilename (ubound (arrsavefilename))) "
if strfiletype="asp" or strfiletype="asa" or strfiletype="aspx" or strfiletype="cer" or strfiletype="cdx" or strfiletype="exe" or strfiletype="rar" or strfiletype="zip" then
uploadfiles=""
replacesaveremotefile=constr
exit function
end if
randomize
rannum=int (900 * rnd) +100
  strfilename=year (dtnow)&right ("0"&​​month (dtnow), 2)&right ("0"&​​day (dtnow), 2)&right ("0"&​​hour (dtnow), 2)&right ("0"&​​minute (dtnow), 2)&right ("0"&​​second (dtnow), 2)&rannum&"."&Strfiletype
re.pattern=temparray (tempi)
  if saveremotefile (savepath&strfilename, remotefileurl)=true then
"********************************
pathtemp=savepath&strfilename
constr=re.replace (constr, pathtemp)
re.pattern=strinstalldir&strchanneldir&"/"
uploadfiles=uploadfiles&"|"&re.replace (savepath&strfilename, "")
else
pathtemp=remotefileurl
constr=re.replace (constr, pathtemp)
"uploadfiles=uploadfiles&" | "&remotefileurl
end if
elseif remotefileurl<>"$false $" and savetf=false then "do not save the picture
re.pattern=temparray (tempi)
constr=re.replace (constr, remotefileurl)
uploadfiles=uploadfiles&"|"&remotefileurl
end if
next
set re=nothing
if uploadfiles<>"" then
uploadfiles=right (uploadfiles, len (uploadfiles) -1)
end if
replacesaveremotefile=constr
end function

Function parameter description:constr:the string to replace

Parameters:savetf:whether to save the file,false not saved, true saved

Parameters:tisturl:current web address

asp