472,790 Members | 1,375 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,790 software developers and data experts.

The BEST "FREE" Pure ASP 10MB File Upload

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
2 7515
jhardman
3,406 Expert 2GB
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
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

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

Similar topics

33
by: Darren Dale | last post by:
I love the language. I love the community. My only complaint is that Python for Windows is built with Visual Studio. It is too difficult to build python, or a module, from source. This is what...
13
by: Mars | last post by:
Why this error occurs?? typedef char *string; int main(void) { string str; str="ajsdklfajsdf"; printf("%s\n",str);
5
by: Michael | last post by:
How can I determine a users PC Total system memory and memory available or free at the time of my program loading. Thanks
5
by: prashantkhoje | last post by:
hi ppl, i am developing an C application in Microsoft visual C++ 6.0. i get following error while running it in debug mode: /* here's the error message */ program: my_application.exe...
16
by: Stef Mientki | last post by:
If I create a large array of data or class, how do I destroy it (when not needed anymore) ? Assign it to an empty list ? thanks, Stef Mientki
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.