The BEST "FREE" Pure ASP 10MB File Upload | Member | | Join Date: Jan 2008
Posts: 85
| |
Hi All,
I found the best pure ASP code to upload a file to either server and/or MS Access Database. It works fine for me however, there is one thing that I don't like and have tried to fix but don't have any luck is to do a form validation. This script requires the files: db-file-to-disk.asp and _upload.asp. There is a DESCRIPTION field in the db-file-to-disk.asp file, what I want to do is the user has to field out this fied before submitting Submit orelse it will give you an error. Thanks in advance for your help.
db-file-to-disk.asp -
<%
-
'Sample file Field-SaveAs.asp
-
'Store extra upload info to a database
-
' and file contents to the disk
-
Server.ScriptTimeout = 5000
-
-
'Create upload form
-
'Using Huge-ASP file upload
-
'Dim Form: Set Form = Server.CreateObject("ScriptUtils.ASPForm")
-
'Using Pure-ASP file upload
-
Dim Form: Set Form = New ASPForm %><!--#INCLUDE FILE="_upload.asp"--><%
-
-
-
Server.ScriptTimeout = 1000
-
Form.SizeLimit = &HA00000'10MB
-
-
'was the Form successfully received?
-
Const fsCompletted = 0
-
-
If Form.State = fsCompletted Then 'Completted
-
-
'Create destination path+filename for the source file.
-
Dim DestinationPath, DestinationFileName
-
DestinationPath = Server.mapPath("UploadFolder")
-
DestinationFileName = DestinationPath & "\" & Form("SourceFile").FileName
-
-
-
'Open recordset to store uploaded data
-
Dim RS: Set RS = OpenUploadRS
-
-
'Store extra info about upload to database
-
RS.AddNew
-
RS("UploadDT") = Now()
-
RS("Description") = Form.Texts.Item("Description")
-
RS("SourceFileName") = Form("SourceFile").FilePath
-
RS("DestFileName") = DestinationFileName
-
RS("DataSize") = Form("SourceFile").Length
-
'...
-
RS.Update
-
-
Response.write "<br>Source file names:"
-
Dim Field: For Each Field in Form.Files.Items
-
Response.write "<br> " & Field.FileName
-
Next
-
'{b}Save file to the destination
-
Form("SourceFile").SaveAs DestinationFileName
-
'{/b}
-
-
response.write "<Font color=green><br>SourceFile was saved as " & DestinationFileName
-
response.write "<br>See ListFiles table in " & Server.MapPath("upload.mdb") & " database.</Font>"
-
-
ElseIf Form.State > 10 then
-
Const fsSizeLimit = &HD
-
Select case Form.State
-
case fsSizeLimit: response.write "<br><Font Color=red>Source form size (" & Form.TotalBytes & "B) exceeds form limit (" & Form.SizeLimit & "B)</Font><br>"
-
case else response.write "<br><Font Color=red>Some form error.</Font><br>"
-
end Select
-
End If'Form.State = 0 then
-
-
Function OpenUploadRS()
-
Dim RS : Set RS = CreateObject("ADODB.Recordset")
-
-
'Open dynamic recordset, table Upload
-
RS.Open "ListFiles", GetConnection, 2, 2
-
-
Set OpenUploadRS = RS
-
end Function
-
-
Function GetConnection()
-
dim Conn: Set Conn = CreateObject("ADODB.Connection")
-
Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
-
Conn.open "Data Source=" & Server.MapPath("upload.mdb")
-
set GetConnection = Conn
-
end function
-
-
-
-
%>
-
-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
-
<HTML><HEAD>
-
<TITLE>ASP huge file upload sample.</TITLE>
-
<STYLE TYPE="text/css"><!--TD {font-family:Arial,Helvetica,sans-serif }TH {font-family:Arial,Helvetica,sans-serif }TABLE {font-size:10pt;font-family:Arial,Helvetica,sans-serif }--></STYLE>
-
</HEAD>
-
<BODY BGColor=white>
-
-
-
<Div style=width:600>
-
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
-
-
<TR>
-
<TH noWrap align=left width="20%" bgColor=khaki> <A
-
href="http://www.pstruh.cz/help/scptutl/upload.asp">Power ASP
-
file upload</A> - upload to disk, store extra file upload info in a database </TH>
-
<TD> </TD></TR></TABLE>
-
<TABLE cellSpacing=2 cellPadding=1 width="100%" bgColor=white border=0>
-
-
<TR>
-
<TD colSpan=2>
-
<P> This sample demontrates using
-
of Huge-ASP file upload to upload files to server and store file path in server-side database.
-
The sample ASP file is running with Microsoft.Jet.OLEDB (MDB) connection, but you can use it
-
with any other SQL server or file drivers (MS SQL server, Oracle, MySQL, FoxPro driver, etc.).
-
</P>
-
<P>
-
You can select source file and write some description of the file.
-
Source file is stored on server disk. Description, file name, file size and path to stored file are saved in server-side database along with current upload time.
-
</P>
-
Form size limit is <%=Form.SizeLimit%>B (<%=Form.SizeLimit \ 1024 %>kB - you can change it, see source) .
-
</TD></TR></TABLE>
-
-
-
-
-
<TABLE cellSpacing=1 cellPadding=3 bordercolor=silver bgcolor=GAINSBORO width="" border=1>
-
<form method=post ENCTYPE="multipart/form-data">
-
<TR>
-
<TD> </TD>
-
<TD Align=Right><input type="submit" Name="Action" value="Upload the file >>"></TD>
-
</TR>
-
<TR>
-
<TD>File to upload</TD>
-
<TD><input type="file" name="SourceFile"></TD>
-
</TR>
-
<TR>
-
<TD>Description</TD>
-
<TD><textarea cols="60" rows="8" name="Description">Type description of the file.</textarea></TD>
-
</TR>
-
-
</form></Table>
-
-
-
-
-
<HR COLOR=silver Size=1>
-
<CENTER>
-
<FONT SIZE=1>© 1996 – <%=year(date)%> Antonin Foller, <a href="http://www.pstruh.cz">PSTRUH Software</a>, e-mail <A href="mailto:help@pstruh.cz" >help@pstruh.cz</A>
-
<br>To monitor current running uploads/downloads, see <A Href="http://www.pstruh.cz/help/iistrace/iis-monitor.asp">IISTracer - IIS real-time monitor</A>.
-
</FONT>
-
-
</CENTER>
-
</Div>
-
</BODY></HTML>
|  | Moderator | | Join Date: Jan 2007 Location: logan, utah
Posts: 2,690
| | | re: The BEST "FREE" Pure ASP 10MB File Upload
If it was me, I would add a javascript function called onClick (I would remove the submit button, and use a fake button instead) that checks the input and either submits the form, or posts an alert message.
Jared
BTW, thanks for posting the code, a lot of people have asked for that type of thing.
| | Member | | Join Date: Jan 2008
Posts: 85
| | | re: The BEST "FREE" Pure ASP 10MB File Upload
Hi Jhardman,
Thanks. I got it working. Below is the link to the PURE 10MB ASP Upload Code. It has a bunch of features with upload progress bar .... pretty nice one.
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=8225&lngWId=4
| Similar ASP / Active Server Pages bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,327 network members.
|