473,388 Members | 1,340 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 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 7606
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.