473,703 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File Upload and Update Contents - Please Help

85 New Member
Hi Master CroCrew,

I found a good PURE ASP that will allow you to upload 10MB file to the server and the file contents such as Network, Author, Title, etc... will insert to MS Access at the same time.

Below is a working script that I used. Let's say after the file is uploaded to the server and a record created with the file contents above to the MS Access (using the script below). If I want to UPDATE that record let's say, change the Author from Mr. A to Mr. B, the new file will overwrite the existing one on the server OK however, how can I modify the RS.AddNew code to make it to UPDATE the MS Access contents such as Author as well? Thank you very much for your OUTSTANDING SUPPORT so far. FYI that the website where the original script located is

http://www.planet-source-code.com/vb...=8225&lngWId=4
Expand|Select|Wrap|Line Numbers
  1. <%
  2. Server.ScriptTimeout = 5000
  3.  
  4. Dim Form: Set Form = New ASPForm %><!--#INCLUDE FILE="_upload.asp"--><%
  5.  
  6.  
  7. Server.ScriptTimeout = 1000
  8. Form.SizeLimit = &HA00000'10MB
  9.  
  10. If len(Request.QueryString("UploadID"))>0 then
  11.   Form.UploadID = Request.QueryString("UploadID")'{/b}
  12. End if
  13.  
  14. Const fsCompleted  = 0
  15.  
  16. Dim UploadID, PostURL
  17. UploadID = Form.NewUploadID
  18.  
  19. 'Send this ID as a UploadID QueryString parameter to this script.
  20. PostURL = Request.ServerVariables("SCRIPT_NAME") & "?UploadID=" & UploadID'{/b}
  21.  
  22. %>
  23.  
  24. <HTML>
  25. <HEAD>
  26. <TITLE>Testing</TITLE>
  27. </HEAD>
  28.  
  29. <BODY BGCOLOR="#FFFFFF">
  30.  
  31. <TABLE>
  32. <BR>
  33. <DIV ALIGN="LEFT">
  34. <FORM NAME="file_upload" METHOD="POST" ENCTYPE="multipart/form-data" OnSubmit="return ProgressBar();" Action="<%=PostURL%>">
  35.  
  36.   &nbsp;&nbsp;&nbsp;&nbsp;<FONT FACE="HELVETICA,HELV,ARIAL" SIZE="2" COLOR="FF0000">** Denotes REQUIRED FIELD.  Please DO NOT press the "Upload File" button twice.</FONT>
  37.      <P></P>
  38.  
  39.     <TR>
  40.         <TD ALIGN="LEFT"><FONT FACE="HELVETICA,HELV,ARIAL" SIZE="2">&nbsp;&nbsp; Network</FONT></FONT><FONT FACE="HELVETICA,HELV,ARIAL" SIZE="1" COLOR="FF0000">&nbsp;&nbsp; ** </FONT></TD>
  41.             <TD>
  42.                                         <SELECT NAME="Network" ID="Network">
  43.                                                     <OPTION VALUE>                                                                                        </OPTION>
  44.                                                     <OPTION VALUE="TEST1"> TEST1                                                                </OPTION>
  45.                              <OPTION VALUE="TEST2"> TEST2                                                                    </OPTION>      
  46.                              </SELECT>
  47.  
  48.                              <FONT FACE="HELVETICA,HELV,ARIAL" SIZE="2">&nbsp;&nbsp; Author</FONT><FONT FACE="HELVETICA,HELV,ARIAL" SIZE="1" COLOR="FF0000">&nbsp;&nbsp; ** </FONT>
  49.                                 <INPUT TYPE="TEXT" NAME="Author" SIZE="40" VALUE="" ID="Author">
  50.  
  51.                                 <FONT FACE="HELVETICA,HELV,ARIAL" SIZE="2">&nbsp;&nbsp; Revision</FONT><FONT FACE="HELVETICA,HELV,ARIAL" SIZE="1" COLOR="FF0000">&nbsp;&nbsp; ** </FONT>
  52.                                 <INPUT TYPE="TEXT" NAME="Revision" SIZE="8" VALUE="" ID="Revision">
  53.              </TD>
  54.     </TR>
  55.  
  56.     <TR>
  57.             <TD ALIGN="LEFT"><FONT FACE="HELVETICA,HELV,ARIAL" SIZE="2">&nbsp;&nbsp; Title</FONT><FONT FACE="HELVETICA,HELV,ARIAL" SIZE="1" COLOR="FF0000">&nbsp; ** </FONT></TD>
  58.             <TD><INPUT TYPE="TEXT" NAME="Title" SIZE="99" VALUE="" ID="Title"></TD>
  59.     </TR>
  60.  
  61.     <TR>
  62.             <TD ALIGN="LEFT"><FONT FACE="HELVETICA,HELV,ARIAL" SIZE="2">&nbsp;&nbsp; File Name</FONT><FONT FACE="HELVETICA,HELV,ARIAL" SIZE="1" COLOR="FF0000">&nbsp;&nbsp; ** </FONT></TD>
  63.             <TD><INPUT TYPE="FILE" NAME="SourceFile" SIZE="86" VALUE="" ID="SourceFile"></TD>
  64.     </TR>
  65.  
  66. </TABLE>
  67.     <CENTER>
  68.     <BR>
  69.     <INPUT CLASS="Table_Blue" TYPE="SUBMIT" VALUE="UPLOAD FILE"> &nbsp;&nbsp;&nbsp;&nbsp;<INPUT CLASS="Table_Blue" TYPE="RESET" VALUE="CLEAR FORM">
  70.     </CENTER>
  71.     <BR>
  72. <CENTER>
  73. <%
  74.  
  75. If Form.State = fsCompleted Then 'Completed
  76.  
  77.   'Create destination path+filename for the source file.
  78.   Dim DestinationPath, DestinationFileName
  79.   DestinationPath = Server.mapPath("MOPsUpload")
  80.   DestinationFileName = DestinationPath & "\" & Form("SourceFile").FileName
  81.  
  82.  
  83.   'Open recordset to store uploaded data
  84.   Dim RS: Set RS = OpenUploadRS
  85.  
  86.   'Store extra info about upload to database
  87.   RS.AddNew
  88.    RS("UploadDT") = Date()
  89.    RS("Network") = Form.Texts.Item("Network")
  90.    RS("Title") = Form.Texts.Item("Title")
  91.    RS("Revision") = Form.Texts.Item("Revision")
  92.    RS("Author") = Form.Texts.Item("Author")
  93.    RS("SourceFileName") = Form("SourceFile").FilePath
  94.    RS("DestFileName") = DestinationFileName
  95.    RS("DataSize") = Form("SourceFile").Length
  96.    '...
  97.   RS.Update
  98.  
  99.   Dim Field: For Each Field in Form.Files.Items
  100.   Next
  101.   'Save file to the destination
  102.   Form("SourceFile").SaveAs DestinationFileName
  103.  
  104.         Response.Write("<FONT FACE=""HELVETICA,HELV,ARIAL"" COLOR=""#FF0000"" SIZE=""2"">Uploaded successfuly.")
  105.     Response.Write("</FONT>")
  106.  
  107. ElseIf Form.State > 10 then
  108.   Const fsSizeLimit = &HD
  109.   Select case Form.State
  110.         case fsSizeLimit: response.write  "<br><Font Color=red>Source form size (" & Form.TotalBytes & "B) exceeds form limit (" & Form.SizeLimit & "B)</Font><br>"
  111.         case else response.write "<br><Font Color=red>Some form error.</Font><br>"
  112.   end Select
  113. End If'Form.State = 0 then
  114.  
  115. Function OpenUploadRS()
  116.   Dim RS  : Set RS = CreateObject("ADODB.Recordset")
  117.  
  118.   'Open dynamic recordset, table Upload
  119.   RS.Open "MOPs", GetConnection, 2, 2
  120.  
  121.   Set OpenUploadRS = RS
  122. End Function
  123.  
  124. Function GetConnection()
  125.     Set Conn = Server.CreateObject("ADODB.Connection")
  126.     Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("YourDatabase.mdb") & "; Jet OLEDB:Database Password=happy"
  127.     set GetConnection = Conn
  128. End function
  129.  
  130. %>
  131.  
  132. </CENTER>
  133. <BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>
  134. </FORM>
  135. <SCRIPT language=javascript>
  136. //Open window with progress bar.
  137. <!--
  138. function ProgressBar(){
  139.   var ProgressURL;
  140.   ProgressURL = 'progress.asp?UploadID=<%=UploadID%>';
  141.   var Network;
  142.   var Revision;
  143.   var Author;
  144.   var Title;
  145.   var SourceFile;
  146.  
  147. Network = file_upload.Network.value;
  148. Revision = file_upload.Revision.value;
  149. Author = file_upload.Author.value;
  150. Title = file_upload.Title.value;
  151. SourceFile = file_upload.SourceFile.value;
  152.  
  153. if (Network.length==0)
  154. {
  155.     alert('Reason:  The "Network" may contain invalid characters or is blank.');
  156.     file_upload.Network.focus();
  157.     return false;
  158. }
  159.  
  160. else
  161. {
  162.   var v = window.open(ProgressURL,'_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=355,height=140');
  163.     return true;
  164. }
  165.   //return;
  166. }
  167. // -->
  168. </SCRIPT>
  169.  
  170. </DIV>
  171. </TD>
  172.  
  173.  
  174. </BODY>
  175. </HTML>
Feb 2 '08 #1
2 2915
jhardman
3,406 Recognized Expert Specialist
Hey hotflash,

Just a reminder, please put your code inside code tags (notice the button marked - #) This makes it much easier to read.

In order to update rather than add new, you need to do two things:

1- open the recordset and make sure you are on the record you want to update. This is the hard part, you will need to either modify the SQL query so that you only return the one record you want (the preferred way), or open all the records and scroll through until you find the record you want to update (takes longer to run, but may be easier for a newbie to code).

2- remove the "RS.addNew" line. This is the easy part, as long as the recordset doesn't add a new record, you will overwrite the previous data.

Let me know if this helps.

Jared
Feb 4 '08 #2
hotflash
85 New Member
Hi Jared,

Thanks for your replying. I have tried both methods you recommended but still have no luck. There are about 30 records on the database. We only need to update the record that is needed. Honestly, this thing is way over my head.

Any other recommendation? There is a link to the code above, wonder if you can try yourself to see if you have any luck or not. The file that I used is
db-file-to-disk. Let's say, once the file is uploaded to the server, and there is an entry in the database. Try to update the Description to see how is it going to work. Thanks once again for your outstanding support.
Feb 7 '08 #3

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

Similar topics

2
3928
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give them a caption, storing the caption and filename in a text file. It's a bit buggy when removing the photos and captions from the file, and also in displaying them on the delete page. you can see it in action at www.4am.com.au/gallery/upload.php...
2
13838
by: Jake | last post by:
Hi group, I am trying to build a page that allows uploading My ISP only supports Smartupload I am testing on a small hubbed local network, with PWS Any help is appreciated. --------------------- 'rqstupl.asp contents <HTML>
1
1682
by: bballr | last post by:
What I am trying to do is to take the contents of a very large text file and place it into a LONGTEXT field in a database. I am looking for a solution using the C API to help me handle this. The code I use right now is very ineffecient. I basically use a VERY large character array that is like 600,000 characters long and store an UPDATE query to the database in this. I place the contents of the file being uploaded into this query where...
4
5894
by: Jim Michaels | last post by:
after a file upload, $_FILES is not populated but $_POST is. what's going on here? $_POST=C $_POST=C $_POST=C $_POST=C:\\www\\jimm\\images\\bg1.jpg $_FILES= $_FILES= $_FILES=
6
3038
by: Vic Spainhower | last post by:
Hello, I am trying to do a FTP file upload which works fine on my localhost but on my ISP server it fails. I can't seem to find where I can go to find the specific cause of the failure. In both cases the file is being transmitted to the same FTP server and using the same PHP script so it shouldn't be a file size or login credentials problem. Could someone please help me out and give me some ideas what is wrong. I would really...
0
1995
by: aris1234 | last post by:
hello.. How to upload image file in page update ..?? i have logic like this : if user upload new image then old image must delete and update DB used new name if user not upload new image then old image no delete. code form like this (i dontknow this code right or wrong, please correction if wrong) :
3
22046
by: siyaverma | last post by:
i am trying to upload csv file from user's computer to main server the code i am using is if(((isset($_GET)) && ($_GET=="yes")) ) { $typefield = $_GET; echo "<form enctype=\"multipart/form-data\" action=\"$PHP_SELF\" method=\"POST\">
2
2762
by: amritranjan | last post by:
This is my Jsp code for image upload in database: -----------Upload.jsp---------------- <html> <head> <title>Account Details </title> </head> <body bgproperties="fixed" bgcolor="#CCFFFF"> <form method="POST" action="UploadPicture.jsp" enctype="multiform/form-data">
2
7649
by: hotflash | last post by:
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...
0
8759
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
8963
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...
0
7872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5922
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4433
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3125
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
2453
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2069
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.