Checks whether the uploaded image is a valid function, and the trojan cannot change its suffix or add malicious code to the image.

Source: Internet
Author: User

I tried the aspjpeg component today and found that an error occurs when I use the aspjpeg component to process abnormal image files. Haha, this is exactly what we can use to check the validity of the image, encapsulated as a function ~ CopyCodeThe Code is as follows :'-------------------------------------------
'Function name: chkimg
'Usage: Check whether the image file is legal
'Parameter: IMG, image path
'Return value: Boolean Type
'Items: the server must support aspjpeg.
Function chkimg (IMG)
On Error resume next
Chkimg = true
If isnull (IMG) Then chkimg = false: Exit Function
Set chkjpeg = server. Createobject ("persits. jpeg ")
Chkpath = server. mappath (IMG)
Chkjpeg. Open chkpath
If err then
Chkimg = false
End if
If err. Number <> 0 then err. Clear
Set chkjpeg = nothing
End Function

Because aspjpeg can only process files already on the server, we can do this in actual use: First upload the image to a temporary folder, and then check the validity of the image. If it is legal, copy the image to the image storage directory, delete the temporary file, and return the upload success message. If the file is invalid, delete the temporary file and return an error warning.

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: 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.