SoFunction
Updated on 2025-04-10

Asp Prevent uploading of pictures *s from *s

This article shares the principle of * horses to prevent uploading pictures for your reference. The specific content is as follows

First, determine the file size:

if <10 then
  ("<script>alert('You did not choose to upload the file')</script>")
  ("<script>(-1)</script>")
  ()
end if

After uploading the file to the server, determine the dangerous operation characters in the user's file:

set MyFile = ("")
set MyText = (FilePath, 1) 'Read text files
sTextAll = lcase()

set MyFile = nothing
sStr=".getfolder|.createfolder|.deletefolder|.createdirectory|.deletedirectory|.saveas
|||server.|.createobject|execute|activexobject|language="
sNoString = split(sStr,"|") 
for i=0 to ubound(sNoString)
  if instr(sTextAll,sNoString(i)) then
   set filedel = ("")
    FilePath
   set filedel = nothing
   ("<script>alert('The file you uploaded has a problem, the upload failed');();</script>")
   ()
  end if
next

How to prevent * sex pictures from uploading

I've checked this code without any problem, it can block the upload of * pictures

<%
'***************************************************************
'CheckFileType Functions are used to check whether the file is an image file
'The parameter filename is the path to the local file
 'If it's a filejpeg,gif,bmp,pngOne of the pictures,Function returnstrue,Otherwise returnfalse
'***************************************************************
 
const adTypeBinary=1
 
dim jpg(1):jpg(0)=CByte(&HFF):jpg(1)=CByte(&HD8)
dim bmp(1):bmp(0)=CByte(&H42):bmp(1)=CByte(&H4D)
dim png(3):png(0)=CByte(&H89):png(1)=CByte(&H50):png(2)=CByte(&H4E):png(3)=CByte(&H47)
dim gif(5):gif(0)=CByte(&H47):gif(1)=CByte(&H49):gif(2)=CByte(&H46):gif(3)=CByte(&H39):gif(4)=CByte(&H38):gif(5)=CByte(&H61)
 CheckFileType((""))
 
function CheckFileType(filename)
on error resume next
CheckFileType=false
dim fstream,fileExt,stamp,i
fileExt=mid(filename,InStrRev(filename,".")+1)
set fstream=("")

=adTypeBinary
 filename
=0
select case fileExt
case "jpg","jpeg"
stamp=(2)
for i=0 to 1
if ascB(MidB(stamp,i+1,1))=jpg(i) then CheckFileType=true else CheckFileType=false
next
case "gif"
stamp=(6)
for i=0 to 5
if ascB(MidB(stamp,i+1,1))=gif(i) then CheckFileType=true else CheckFileType=false
next
case "png"
stamp=(4)
for i=0 to 3
if ascB(MidB(stamp,i+1,1))=png(i) then CheckFileType=true else CheckFileType=false
next
case "bmp"
stamp=(2)
for i=0 to 1
if ascB(MidB(stamp,i+1,1))=bmp(i) then CheckFileType=true else CheckFileType=false
next
end select

set fseteam=nothing
if <>0 then CheckFileType=false
end function
%>

The above is the analysis of the principle of *s preventing uploading pictures from Asp. I hope it will be helpful to everyone's learning.