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.