How to use ASP & aspSmartUpload - Upload file to Database This is learn/tutorial asp developers how to using ASP script upload file by aspSmartUpload and insert into Database.
ShotDev Focus:
- ASP & Upload file by aspSmartUpload and insert into Database.
Example
asp_upload7.asp
<% Option Explicit %> <html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <form action="asp_upload8.asp" method="post" enctype="multipart/form-data" name="frmMain"> Upload <input name="file1" type="file"> <input type="submit" name="Submit" value="Submit"> </form> </body> </html>
asp_upload8.asp
<% Option  Explicit %>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<%
Dim mySmartUpload
Dim Conn,strSQL,objExec
'*** Create Object ***'
Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")
'*** Upload Files ***'
mySmartUpload.Upload
'*** Upload file1 ***'
If mySmartUpload.Files("file1").FileName <> "" Then
mySmartUpload.Files("file1").SaveAs(Server.MapPath("MyFiles/" & mySmartUpload.Files("file1").FileName))
Response.write mySmartUpload.Files("file1").Name & " Uploaded.<br>"
'*** Insert Record ***'
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("db/mydatabase.mdb"),"" , ""
strSQL = ""
strSQL = strSQL &"INSERT INTO files "
strSQL = strSQL &"(FilesName) VALUES ('"&mySmartUpload.Files("file1").FileName&"')"
Set objExec = Conn.Execute(strSQL)
End If
Response.write("<a href=asp_upload9.asp>View files</a>")
'*** Properties ***'
'Response.Write("Name = " & mySmartUpload.Files("file1").Name & "<BR>")
'Response.Write("Size = " & mySmartUpload.Files("file1").Size & "<BR>")
'Response.Write("FileName = " & mySmartUpload.Files("file1").FileName & "<BR>")
'Response.Write("FileExt = " & mySmartUpload.Files("file1").FileExt & "<BR>")
'Response.Write("FilePathName = " & mySmartUpload.Files("file1").FilePathName & "<BR>")
'Response.Write("ContentType = " & mySmartUpload.Files("file1").ContentType & "<BR>")
'Response.Write("ContentDisp = " & mySmartUpload.Files("file1").ContentDisp & "<BR>")
'Response.Write("TypeMIME = " & mySmartUpload.Files("file1").TypeMIME & "<BR>")
'Response.Write("SubTypeMIME = " & mySmartUpload.Files("file1").SubTypeMIME & "<BR>")
Set mySmartUpload = Nothing
%>
</body>
</html>
asp_upload9.asp
<% Option  Explicit %>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<%
Dim Conn,strSQL,objRec
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("db/mydatabase.mdb"),"" , ""
strSQL = "SELECT * FROM files "
Set objRec = Server.CreateObject("ADODB.Recordset")
objRec.Open strSQL, Conn, 1,3
%>
<table width="200" border="1">
<tr>
<th width="50"> <div align="center">Files ID </div></th>
<th width="150"> <div align="center">Files Name </div></th>
</tr>
<%
While Not objRec.EOF
%>
<tr>
<td><div align="center"><%=objRec.Fields("FilesID").Value%></div></td>
<td><center><a href="MyFiles/<%=objRec.Fields("FilesName").Value%>"><%=objRec.Fields("FilesName").Value%></a></center></td>
</tr>
<%
objRec.MoveNext
Wend
%>
</table>
<%
objRec.Close()
Conn.Close()
Set objRec = Nothing
Set Conn = Nothing
%>
</body>
</html>
Create a asp file and save to path root-path/myasp/
Run
http://localhost/myasp/asp_upload7.asp
Screenshot
			


3excruciating…
…