A method to prevent garbage images in the news system

zhaozj2021-02-16  42

The more news systems are now uploaded in the news system to achieve a better effect. However, the problem also came, and some pictures were passed up, found that this picture is not right, it can only delete it in the editor, or, in the addition of the local run, there is a problem, and cause the spam produce. In order to prevent spam in this process, many people have studied a lot of ways, such as the mobile network forum, each file uploaded, there is a corresponding record in the database, so that you have to take a table. To store, and if there is an abnormality in the system when adding data to the database, it is also unable to avoid the generation of these garbage. After some of my practice, I studied my way, and now I contribute it for everyone's ax. My method process is this: When the adder of the article logs in to the system, create a temporary work folder by the system, such as "editor" user ID is 5, I created a tempo work catalog of TEMP5 When he adds an article, the uploaded pictures and other attachments are not stored in the directory that is really displayed, but there is this temporary working directory. At the same time, in order to facilitate management, I recommend to build a directory for each news to store these pictures. When the article is submitted, the picture address inside the system is submitted, and the picture in the article is transferred to these corresponding directories. When news or article changes, you will first transfer all the images below this folder to the temporary working directory of the entry, and the image path in the article is replaced, and it is also the same time when saved. process. When the article is deleted, the directory can be deleted, which can guarantee that there is no garbage picture in the process of adding, modifying, and deleting. When the user logs out, the system can delete the corresponding working directory so that there is no garbage generation. Seeing these text descriptions may have dizzy, look at the specific implementation process (because I am more familiar with the ASP, so I use ASP to implement it, and other platforms can be implemented).

First, let me introduce a class I wrote, used to analyze and transfer pictures, detailed description, please see my article: Automatically parse the image address in the page with ASP, save it to the local server ( http://www.9cbs.net/develop/read_article.asp?id=15585)class blacksmith'The Class "blacksmith" is Created by Linzhang Chen'It could use for copy images form other server which contain in the webdim size, baseurl, basefilename, tofolder, servername, processstr, firstoldimg, firstnewimg public Function saveimage (from, tofile) Dim geturl, objStream, imgs, s If size = "" Then size = 0 End If geturl = Trim (from) imgs = getHTTPPage ( geturl) s = size * 512 If Len (imgs)> s Then Set objStream = CreateObject ( "ADODB.Stream") objStream.Type = 1 objStream.Open objStream.Write imgs objStream.SaveToFile tofile, 2 objStream.Close Set objStream = Nothing saveimage = True Else saveimage = False End If End Functionprivate Function getHTTPPage (url) On Error Resume Next Dim http Set http = CreateObject ( "MSXML2.XMLHTTP") http.Open "GET", url, False http.send If http. ReadyState <> 4 THEN EXIXT FUNCTION End if gethttppage = http.responsebody set htt P = Nothing if Err.Number <> 0 Then Err.clear End Function

private Function getimgs (str) getimgs = "" Set objRegExp1 = New RegExp objRegExp1.IgnoreCase = True objRegExp1.Global = True objRegExp1.Pattern = "http:? //. " "" Set mm = objRegExp1.Execute (str) For Each Match1 in mm getimgs = getimgs & "||" & left1.value, len (match1.value) - 1) Next End Function

Function str2img () DIM ServerName, Objregexp, Strs, Matches, Retstr, Arrimg, Newimg, I, FNAME, State, ArrNew, Arrall IF BaseURL <> "" "The IF Right (BaseURL, 1) <>" / "THEN BASEURL = baseurl & "/" End If end if if right (tofolder, 1) <> "/" then tofolder = tofolder & "/" end if Set objRegExp = New RegExp objRegExp.IgnoreCase = True objRegExp.Global = True objRegExp.Pattern = " "strs = trim (processstr) set matches = objRegexp.execute (strs) for Each Match in matches retrstr = Retstr & Getimgs (match.value) Next Arrimg = split (Retstr," || ") Allimg = "" Newimg = "" for i = 1 to Ubound (arrimg) IF Arrimg (i) <> "and INSTR (Allimg, Arrimg (i)) <1 THEN FNAME1 = BASEURL & CSTR (BaseFileName & I & MID) Arrimg (i), INSTRREV (Arrimg (i), "))))) fname = Tofolder & CSTR (ARRIMG (i), Instrrev (Arrimg (i),"))) states = SaveImage (Arrimg (I), FNAME) if states = true kil = allimg & "||" & arrimg (i) newimg = newimg & "||" & fname1 end if end if next arrnew = split (newi MG, "||") arren = split (allimg, "||") for i = 1 to ubound (arrnew) if i = 1 Then firstToldImg = arrll (1) firstnewimg = arrnew (1) end if strs = replace STRS, ARRALL (I), Arrnew (i)) Next str2img = strs end functionered Class When the user is logged in: Because there is a work area, it is best not to let multiple users use the same account to use the same account. When you are out, you will cause loss of other people. The most important process here is that the account is logged in, and the account lock is not allowed to log in (mainly by the FSO and database, I will not say much).

When processing file upload, you can upload a component of Daoxiang's old agriculture, transfer the picture to the workspace. And put the picture code to the editor, after commit, these pictures will be processed by the following code, I am creating folders based on the ID of the news or article: SQL = "SELECT TOP 1 FORM News Where id is null" SET RS = Server.createObject ("AdoDb.Recordset") RS.Open SQL, CONN, 1, 3RS.AddNewRS ("UserID") = session ("myid") 'Because it is new, first plus one Once Idrs.UpdateNewID = RS ("newsid") 'In most cases, this can get the ID, but for the insurance, it is best to judge RS.Closset RS = Nothingif newsid = "" THENSET RS = conn .execute ("SELECT TOP 1 NEWSID from News Where Userid =" & session ("MyID") & "Order By Newsid") NewsId = RS ("NewsID") end ifbasefoder = server.mappath ("photo") 'hypothesis Image Save to the current directory below the photo of the set fso = server.createObject ("scripting.filesystemObject") filepath = basefoder & "& news) 'Suppose will be the content of the news, call me below the contents of the contents of the variable content. That class BlackSmith is handled by the content of the analysis article, and handles the transfer of the picture. SET BS = new blacksmithbs.size = 1bs.baseURL = "photo /" & news "gives the image Add the address of the directory BS.BASEFILENAME =" mynews "to the picture Plus the prefix bs.servername = "" "BS.TOFOLDER = filepathbs.processStr = ContentContent = BS.S.STR2IMGSET BS = Nothing 'Next is the preservation process of news content, I will save it here, and other systems should be Like

Use: 'Creating a Work Directory SET FSO = Server.createObject ("Temp" & session ("MyID")) ifPath = Server.MAppath ("Temp") ("miid")) = server.folderexists (FilePath) Thenfso.createFolder (FilePath) endiff

转载请注明原文地址:https://www.9cbs.com/read-24804.html

New Post(0)