Now the web page-based HTML editor is used in the news system, the article system is getting wider and wider, and a web page can maintain the original style, while the picture can be kept in this page. But during use, if the picture in the paste page is deleted, you will leave a big "X" on your own page, affecting the beautiful view. I had to save this picture before, and then upload it to the server, so it is really troublesome. Can you let the server download the image to save the link on the server and replace the link on the page? The answer is yes. To achieve this feature requires three steps: 1. Get the address of the image in the home page. There are many ways, you can use a split string or by regular matching. Practice has proved that the regular match is the most simple. The address of the analysis picture is saved in the label. We can get all this label first. The process is as follows: set objRegexp = new regexp 'Settings the configuration object objRegexp.Ignorecase = true' ignore the case ObjregExp.global = true 'set to full-text search objRegexp.pattern = "
"'To ensure accurate removal of the picture address, it is divided into two layers: first find the inside
Label, then remove the getImgs function behind the image address inside is the implementation of the implementation.
STRS = TRIM (STR)
Set matches = objRegexp.execute (strs) 'begins to perform configuration
For Each Match in matches
Retstr = Retstr & Getimgs (match.value) 'Executes the second round of matching
NEXT
All pictures are in this SRC = "http: // picture address", so it can be used to achieve the exact picture address: function getimgs (str) getimgs = "" set objregexp1 = new regexpobjregexp1.ignorecase = trueobjregexp1. Global = trueobjregexp1.pattern = "http://. ?" "'Remove the address in the address SET MM = Objregexp1.execute (str) for each match1 in mmgetimgs = getimgs &" || "& left (match1.value, len) Match1.value) -1) 'Take the address in the back of Nextend Function
We have the address of all pictures, we can do the second step. Second, download the picture and save it on the server. This can also be divided into two steps: one is the content of the picture and the other is saved on the server. The content of the picture is implemented by the following function: function gethttppage (URL) on error resume nextdim httpset http = server.createObject ("msxml2.xmlhttp") 'Using XMLHTTP method to get the picture of the picture http.open "Get ", url, falsehttp.send () if http.readystate <> 4 THEN EXIT functionEND IFETHTTPPAGE = http.responsebodyset http = Nothingif err.number <> 0 Then Err.Clear End Function gets the picture content to save, give one The feeling is that it can be used in FSO, but it is actually not, so that the save program will be wrong because the FSO does not support streaming files, so we have to call another object: ado.strem. Specific process is as follows: function process with Hugh content saveimage (from, tofile) dim geturl, objStream, imgsgeturl = trim (from) imgs = gethttppage (geturl) 'get the picture Set objStream = Server.CreateObject ( "ADODB.Stream" ) 'Establish AdoDB.Stream objects, you must have ADO 2.5 or above ObjStream.Type = 1' Open ObjStream.OpenObjstream.Write Imgs 'in binary mode to write string contents to buffer Objstream.savetofile Server.mAppath (Tofile), 2' - Write the buffered content writes ObjStream.close () 'Close the object set objstream = Nothingend function, so as long as one loop is saved all the pictures of the addresses you have, the specific process is as follows: arrimg = split (RetStr, " || ") 'Split String, acquire the list address list allimg =" "newimg =" "for i = 1 to Ubound (arrimg) IF Arrimg (i) <>" and INSTR (Allimg, Arrimg (i)) < 1 THEN 'Look at this picture has been downloaded with FName = Baseurl & CSTR (I & MID (Arrimg (i), "))) SaveImage (arrimg (i), fname)' saves the address of the address, process See above allimg = allimg & "| & arrimg (i) 'puts up the address of the saved picture to determine the address to be replaced newimg = newimg &" | "& fname" back the local address string end ifnext Three steps is to replace the original address.