By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,068 Members | 1,734 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,068 IT Pros & Developers. It's quick & easy.

The BEST "FREE" Pure ASP 10MB File Upload

P: 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
Expand|Select|Wrap|Line Numbers
  1. <%
  2. 'Sample file Field-SaveAs.asp 
  3. 'Store extra upload info to a database
  4. ' and file contents to the disk
  5. Server.ScriptTimeout = 5000
  6.  
  7. 'Create upload form
  8. 'Using Huge-ASP file upload
  9. 'Dim Form: Set Form = Server.CreateObject("ScriptUtils.ASPForm")
  10. 'Using Pure-ASP file upload
  11. Dim Form: Set Form = New ASPForm %><!--#INCLUDE FILE="_upload.asp"--><% 
  12.  
  13.  
  14. Server.ScriptTimeout = 1000
  15. Form.SizeLimit = &HA00000'10MB
  16.  
  17. 'was the Form successfully received?
  18. Const fsCompletted  = 0
  19.  
  20. If Form.State = fsCompletted Then 'Completted
  21.  
  22.   'Create destination path+filename for the source file.
  23.   Dim DestinationPath, DestinationFileName
  24.   DestinationPath = Server.mapPath("UploadFolder")
  25.   DestinationFileName = DestinationPath & "\" & Form("SourceFile").FileName
  26.  
  27.  
  28.   'Open recordset to store uploaded data
  29.   Dim RS: Set RS = OpenUploadRS
  30.  
  31.   'Store extra info about upload to database
  32.   RS.AddNew
  33.    RS("UploadDT") = Now()
  34.    RS("Description") = Form.Texts.Item("Description")
  35.    RS("SourceFileName") = Form("SourceFile").FilePath
  36.    RS("DestFileName") = DestinationFileName
  37.    RS("DataSize") = Form("SourceFile").Length
  38.    '...
  39.   RS.Update
  40.  
  41.   Response.write "<br>Source file names:"
  42.   Dim Field: For Each Field in Form.Files.Items
  43.     Response.write "<br>&nbsp;" & Field.FileName
  44.   Next
  45.   '{b}Save file to the destination
  46.   Form("SourceFile").SaveAs DestinationFileName
  47.   '{/b}
  48.  
  49.   response.write "<Font color=green><br>SourceFile was saved as " & DestinationFileName
  50.   response.write "<br>See ListFiles table in " & Server.MapPath("upload.mdb") & " database.</Font>"
  51.  
  52. ElseIf Form.State > 10 then
  53.   Const fsSizeLimit = &HD
  54.   Select case Form.State
  55.         case fsSizeLimit: response.write  "<br><Font Color=red>Source form size (" & Form.TotalBytes & "B) exceeds form limit (" & Form.SizeLimit & "B)</Font><br>"
  56.         case else response.write "<br><Font Color=red>Some form error.</Font><br>"
  57.   end Select
  58. End If'Form.State = 0 then
  59.  
  60. Function OpenUploadRS()
  61.   Dim RS  : Set RS = CreateObject("ADODB.Recordset")
  62.  
  63.   'Open dynamic recordset, table Upload
  64.   RS.Open "ListFiles", GetConnection, 2, 2
  65.  
  66.   Set OpenUploadRS = RS
  67. end Function 
  68.  
  69. Function GetConnection()
  70.   dim Conn: Set Conn = CreateObject("ADODB.Connection")
  71.   Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
  72.   Conn.open "Data Source=" & Server.MapPath("upload.mdb") 
  73.     set GetConnection = Conn
  74. end function
  75.  
  76.  
  77.  
  78. %>  
  79.  
  80. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  81. <HTML><HEAD>
  82.  <TITLE>ASP huge file upload sample.</TITLE>
  83.  <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>
  84. </HEAD>
  85. <BODY BGColor=white>
  86.  
  87.  
  88. <Div style=width:600>
  89. <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  90.  
  91.   <TR>
  92.     <TH noWrap align=left width="20%" bgColor=khaki>&nbsp;<A 
  93.       href="http://www.pstruh.cz/help/scptutl/upload.asp">Power ASP 
  94.       file upload</A> - upload to disk, store extra file upload info in a database&nbsp;</TH>
  95.     <TD>&nbsp;</TD></TR></TABLE>
  96. <TABLE cellSpacing=2 cellPadding=1 width="100%" bgColor=white border=0>
  97.  
  98.   <TR>
  99.     <TD colSpan=2>
  100.       <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;This sample demontrates using 
  101.       of Huge-ASP file upload to upload files to server and store file path in server-side database. 
  102.             The sample ASP file is running with Microsoft.Jet.OLEDB (MDB) connection, but you can use it 
  103.             with any other SQL server or file drivers (MS SQL server, Oracle, MySQL, FoxPro driver, etc.).
  104.             </P>
  105. <P>
  106. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;You can select source file and write some description of the file.
  107. 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.
  108. </P>
  109. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Form size limit is <%=Form.SizeLimit%>B (<%=Form.SizeLimit \ 1024 %>kB - you can change it, see source) .
  110.   </TD></TR></TABLE>
  111.  
  112.  
  113.  
  114.  
  115. <TABLE cellSpacing=1 cellPadding=3 bordercolor=silver bgcolor=GAINSBORO width="" border=1>
  116. <form method=post ENCTYPE="multipart/form-data">
  117. <TR>
  118.  <TD>&nbsp;</TD>
  119.  <TD Align=Right><input type="submit" Name="Action" value="Upload the file &gt;&gt;"></TD>
  120. </TR>
  121. <TR>
  122.  <TD>File to upload</TD>
  123.  <TD><input type="file" name="SourceFile"></TD>
  124. </TR>
  125. <TR>
  126.  <TD>Description</TD>
  127.  <TD><textarea cols="60" rows="8" name="Description">Type description of the file.</textarea></TD>
  128. </TR>
  129.  
  130. </form></Table>
  131.  
  132.  
  133.  
  134.  
  135. <HR COLOR=silver Size=1>
  136. <CENTER>
  137. <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>
  138. <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>.
  139. </FONT>
  140.  
  141. </CENTER>
  142. </Div>
  143. </BODY></HTML>
Jan 26 '08 #1
Share this Question
Share on Google+
2 Replies


jhardman
Expert 2.5K+
P: 3,405
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.
Jan 29 '08 #2

P: 85
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
Jan 30 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.