File Upload Code

Source: Internet
Author: User
Tags file upload

File Upload code , this upload code do not know when I wrote, haha or also take out the bar,

<%
Dim Filename,filepath,filetype,obstream,fso,fod,sql ' defines a variable
Filepath=request. Form ("filename" gets the file path
If Len (filepath) =0 or InStr (filepath, "' <>0 then ' the legality of the path
Response. Redirect ("firstfile.asp?info= file is illegal"
Else
Filename=mid (Filepath,instrrev (filepath, "\" + 1) ' Get filename
Filetype=mid (Filename,instrrev (FileName, ".") +1) ' Get file type
Imagepath=server.mappath ("image"
If InStr (filetype, "jpg" <>0 or InStr (filetype, "gif" <>0 or InStr (filetype, "png" <>0 Then ' judge whether the file we want to upload
Set Fso=server.createobject ("Scripting.FileSystemObject"
Set Fod=fso.getfolder (ImagePath)
For each F in fod.files
F=mid (F,instrrev (f, "\" + 1)
If F=filename then ' determine if the file exists
Response. Redirect ("firstfile.asp?info= file already exists"
End If
Next
Set fso=nothing
Set Obstream=server.createobject ("ADODB.stream"
Obstream.type=1
Obstream.open
Obstream.loadfromfile filepath
Path= "Image\" &filename
If obstream.size<500*1024 Then

Sql= "SELECT * from Jimmy"
Call OPENDB ()
Rs.Open sql,cnn,1,3
Rs.addnew
RS ("Image_path" =path
Rs.update
Call Closedb ()
Obstream.savetofile Server.MapPath (path) ' Upload file
Response. Redirect ("firstfile.asp?info= upload file succeeded"
End If
Obstream.close
Set obstream=nothing
Else
Response. Redirect ("firstfile.asp?info= file is not valid, must be a picture file Jpg,gif,png,"
End If
End If

%>

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.