473,888 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The BEST "FREE" Pure ASP 10MB File Upload

85 New Member
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 7661
jhardman
3,406 Recognized Expert Specialist
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
hotflash
85 New Member
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?tx tCodeId=8225&ln gWId=4
Jan 30 '08 #3

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

Similar topics

33
2994
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 open source is all about, isnt it? I even have a copy of visual studio, and I still cant build modules from source, because my academic copy is version 7. As a scientist funded by the NSF, I feel compelled to do all my work using free software (I...
13
1693
by: Mars | last post by:
Why this error occurs?? typedef char *string; int main(void) { string str; str="ajsdklfajsdf"; printf("%s\n",str);
5
5772
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
2055
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 DAMAGE: after Block number (#41) at 0x002F51C0
16
17957
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
9961
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9800
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10778
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10885
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10439
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7990
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4642
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4244
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3252
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.