Program implementation function: Automatically Downloads images from files on the remote page to the local server
'Save the following as save2local. asp
'Test: save2local. asp? Url = http://ent.sina.com.cn/s/m/2003-11-11/1411231388.html
<%
'Parameter settings start
Url = request ("url ")
Localaddr = server. MapPath ("images_remote/") 'is saved to the local directory.
Localdir = "images_remote/" 'relative path of http access
AllowFileExt = "jpg | bmp | png | gif" 'supported file name formats
'Parameter set
If createdir (localaddr) = false then
Response. Write "failed to create directory. Please check the directory permission"
Response. End
End if
Response. Write Convert2LocalAddr (url, localaddr, localdir)
Function Convert2LocalAddr (url, localaddr, localdir)
'Parameter description
'URL page address
'Localaddr saves the local physical address
'Localdir relative path
StrContent = getHTTPPage (url)
Set objRegExp = New Regexp
ObjRegExp. IgnoreCase = True
ObjRegExp. Global = True
ObjRegExp. Pattern = " "
Set Matches = objRegExp. Execute (strContent)
For Each Match in Matches
RetStr = RetStr & GetRemoteImages (Match. Value)
Next
ImagesArray = split (RetStr, "| ")
RemoteImage = ""
LocalImage = ""
For I = 1 to ubound (ImagesArray)
If ImagesArray (I) <> "" and instr (RemoteImage, ImagesArray (I) <1 then
Fname = baseurl & cstr (I & mid (ImagesArray (I), limit Rev (ImagesArray (I ),".")))
ImagesFileName = ImagesArray (I)
AllowFileExtArray = split (AllowFileExt, "| ")
IsGetFile = false
For tmp = 0 to ubound (AllowFileExtArray)
If lcase (GetFileExt (ImagesFileName) = ALlowFileExtArray (tmp) then
IsGetFile = True
End if
Next
If isGetFile = true then
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.