A way to prevent the production of spam pictures in the news system

Source: Internet
Author: User
Tags file upload split trim
The more the news system is now in the news system, the more it supports online uploads to insert pictures in order to achieve better results. But the problem also came, and some pictures passed up, found that the picture is not correct, it can only be deleted in the editor, or, in addition to the system in the process of problems, resulting in the production of garbage pictures. To prevent garbage pictures and attachments from appearing in this process, many people have studied a lot of methods, such as the Dynamic Network forum, on the upload of each file, in the database has a corresponding record, so to occupy a table to store, and if you add data to the database when the system appears abnormal, It is also impossible to avoid the creation of such rubbish. After some of my practice, to study my methods, and now contribute to the treatise for everyone.
My method process is this: when the author of the article is logged into the system, the system to create a temporary working folder, such as "editor" the user ID is 5 then I set up a TEMP5 temporary working directory, when he added the article, The uploaded images and other attachments are not stored in the directory where they are actually to be displayed, but in the temporary working directory. At the same time in order to facilitate management, I suggest that each piece of news to build a directory to store these pictures, when the article submitted, by the system analysis of the picture address, the article inside some of the pictures transferred to these corresponding directories inside. When the news or article changes, first of all the pictures under this folder to enter the temporary working directory, while the article inside the picture path to replace, save the time is also and add when the same process. When the article is deleted, but also to delete this directory, this can ensure that in addition, modify, delete the process of the production of garbage pictures. When the user is logged out, the system can delete the corresponding working directory, so that it can be completely done without garbage production.
See the above text description may be a lot of people to dizziness, then look at the specific implementation of the process it (because I am more familiar with ASP, so I use ASP to implement it, with other platforms can also be achieved). First let me introduce myself to write a class, to analyze and transfer the picture, detailed description Please see my another article: use ASP to automatically resolve the picture address in the Web page, and save it to the local server (http://www.csdn.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 Web
Dim 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 Function

Private 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
Exit Function
End If
Gethttppage = Http.responsebody
Set http = 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 & "| |" & Left (Match1.value, Len (match1.value)-1)
Next
End Function

Function str2img ()
Dim servername, objRegExp, STRs, Matches, Retstr, arrimg, newimg, I, fname, states, Arrnew, Arrall
If baseurl<> "" Then
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 the Match in matches
Retstr = 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 (Basefilename & I & Mid (arrimg (i), InStrRev (Arrimg (i), "."))
states = SaveImage (Arrimg (i), fname)
If states = True Then
allimg = allimg & "| |" & ARRIMG (i)
newimg = newimg & "| |" & FNAME1
End If
End If
Next
Arrnew = Split (newimg, "| |")
Arrall = Split (allimg, "| |")
For i = 1 to UBound (arrnew)
If I=1 Then
Firstoldimg=arrall (1)
Firstnewimg=arrnew (1)
End If
STRs = Replace (STRs, Arrall (i), arrnew (i))
Next
Str2img = STRs
End Function
End Class
The first step when users log in: Because there is a workspace, therefore, it is best not to allow multiple users to use the same account or the time someone logged out, will cause other people's work lost, here is the most important deal is the account login to this account lockout does not allow duplicate login (mainly by the FSO and database to achieve, I will not say more).
When processing file upload, you can use the old farmer's no component upload, the picture uploaded to the workspace. and return the picture code to the editor, when submitted, will be the following code to process these pictures, I here based on the news or the ID of the article to create a folder:
Sql= "SELECT top 1 form news where ID is null"
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open sql,conn,1,3
Rs.addnew
RS ("userid") =session ("myID") ' because it's new, add one to get the ID
Rs.update
Newid=rs ("NewSID") ' in most cases, so that you can get an ID, you can



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.