[Asp common class] Replace remote files with local files and save remote files

Source: Internet
Author: User
I don't know if this is a general class? I am sorry for the lack of solid ASP basic knowledge.





1. download the following text file and change. txt to. asp, which contains specific settings.

Http://www.dongjidao.com/remote.txt

2. Call method:

<! -- # Include file = "remote. asp" -->

Change the following code to the place where the article is stored

Code: [copy to clipboard] If ssavefileselect = true then
RS ("content") = replaceremoteurl (articlecontent, ssavefilepath, sfileext)
Else
RS ("content") = articlecontent
End if

<% 'Whether to save the remote image const ssavefileselect = true' when adding a resource, do not end with "/" const ssavefilepath = "/images/News" 'Remote Image Storage Type const sfileext = "JPG | GIF | BMP | PNG "'////// ////////////////////////////////////////: replace the remote file in the string with a local file and save the Remote File 'parameter: 'shtml: string to be replaced 'ssavepath: Path of the saved file 'sext: execute the replaced Extension function replaceremoteurl (shtml, ssavefilepath, sfileext) dim s_content = shtml if isobjinstalled ("Microsoft. XMLHTTP ") = false then replaceremoteurl = s_content exit function end if Dim re, remotefile, remotefileurl, savefilename, savefiletype, delimiter, arrsavefilename, 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 savefiletype = Replace (replace (remotefileurl, "/", "A"), ":", "A") arrsavefilename = right (savefiletype, 12) Authorization = ssavefilepath & "/" savefilename = ssavefilepaths & arrsavefilename call saveremotefile (savefilename, remotefileurl) s_content = Replace (s_content, remotefileurl, savefilename) next replaceremoteurl = s_contentend function '//////////////////////////////////: save remote file to local 'parameter: localfilename ------ local file name 'remotefileurl ------ Remote File url' return value: True ---- success 'false---- failure sub saveremotefile (s_localfilename, s_remotefileurl) dim ads, retrieval, getremotedata on error resume next set retrieval = server. createobject ("Microsoft. XMLHTTP ") with retrieval. open "get", s_remotefileurl, false ,"","". send getremotedata =. responsebody end with set retrieval = nothing set ads = server. createobject ("ADODB. stream ") with ads. type = 1. open. write getremotedata. savetofile server. mappath (s_localfilename), 2. cancel (). close () end with set ads = nothingend sub '////////////////////////////////: check whether the component has been installed 'parameter: strclassstring ---- component name' return value: True ---- 'false' installed ---- function isobjinstalled (s_classstring) Not Installed) 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 = 0end function %>

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.