Prevents invalid file source code from being uploaded.
Source: Internet
Author: User
After recent debugging, the code section of the log "how to solve invalid files generated by user uploads" written by the madman in April 12 has been completed. You are welcome to criticize and correct your suggestions for improvement.
[FileName]: upload. asp
[Code]:
<% @ LANGUAGE = "VBSCRIPT" CODEPAGE = "936" %>
<! -- # I nclude virtual = "upload. inc" -->
<%
If Request. ServerVariables ("REQUEST_METHOD") = "POST" then
'Form submission and execution
CONST upFileSize = 100 'file size limit, unit: KB
CONST upFileType = ".gif.jpg.jpeg" 'file type restriction, which can be modified as needed
CONST targetPath = "/publish/images/" 'end with "/" as the path for storing files in the root directory of the website
Dim upload, thisFile, formName, iCount
Set upload = new upload_5xSoft '': creates an upload object.
Flag = true' ID of the initial file Upload
For each formName in upload. ifile 'list all parameters of the uploaded file
Set thisFile = upload. ifile (formName) 'to generate a file object
If thisfile. filesize = 0 then
Flag = False
Msg = "select the file you want to upload. "
CALL showErr (Msg)
End if
If thisfile. filesize> upFileSize * 1024 then
Flag = False
Msg = "the file size exceeds the limit. "
CALL showErr (Msg)
End if
If Instr (upFileType, GetExtendName (thisfile. FileName) = 0 then
Flag = False
Msg = "The file format does not meet the requirements. "
CALL showErr (Msg)
End if
If Flag then
'Create a temporary Upload folder
TempPath = "/publish/images/" & Session. SessionID &"/"
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