ASP no component upload Image source code

Source: Internet
Author: User
Tags file upload
Upload | upload pictures | no components | source code

<!--#include file= "Upload_5xsoft.inc"-->
<%
Set conn=server.createobject ("Adodb.connection")
Connstr= "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath ("Db.mdb")
Conn.Open ConnStr
'----------------------------------------
function getextendname (filename)
Extname=lcase (filename)
Extname=right (extname,3)
Extname=right (Extname,3-instr (Extname, "."))
Getextendname=extname
End Function
'---------------------------------------------------

'-------------------------------------------------------
function filename ()
Filename=now ()
Filename=replace (filename, "-", "")
Filename=replace (filename, ":", "")
Filename=replace (FileName, "", "")
Filename=filename
End Function
'----------------------------------------------------------

'-------------------------------------------------------------------
Set Upload=new Upload_5xsoft

Set Upfile=upload.file ("Files")
Title=upload.form ("T1")
Info=upload.form ("T2")

If Upfile.filesize>0 and upfile.filename<> "" Then
If InStr ("Jpg,bmp,gif", Getextendname (upfile.filename)) >0 Then
If upfile.filesize<204800 Then
fname=filename& "." &getextendname (Upfile.filename)
Upfile.saveas Server.MapPath ("pic/" &fname)

sql= "INSERT into IMG (title,info,imgpath) VALUES (' + title +" ', ' "+ info +" ', ' "+ fname +") "
Conn. Execute SQL
Conn.close
Response.Write "<script>alert" (' Add picture Success! '); top.location.href= ' index.asp ';</script> '
Else
Response.Write "<script language= ' JavaScript ' > alert (' File upload failed, size exceeded 200k! ');" History.back (); </script> "
End If
Else
Response.Write "<script language= ' JavaScript ' > alert (' File upload failed, its not picture Format! '); History.back (); </script> "
End If
End If
'--------------------------------------------------------



Related Article

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.