473,608 Members | 2,592 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Uploading Files

1 New Member
I'm a bit of a newbie here. I've learned a lot from reading the posts you all have here. I need some help uploading files using an asp form.

I am using some code that I found from Jacob at asp101.com.
http://www.asp101.com/articles/jacob/scriptupload.asp

My three files are:
Syllabus.htm

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. </head><body>
  6. <table width="500" border="1" frame="box" rules="none" align="center" cellpadding="0" cellspacing="0">
  7. <FORM name="form" ENCTYPE="multipart/form-data" METHOD="POST" ACTION="uploadexmple.asp">
  8.  <tr><TD colspan="4"><strong>Upload syllabus (one file)</strong></td>
  9. </tr><tr><td colspan="4"><INPUT TYPE=FILE SIZE=50 NAME="FILE1"></td></tr><TR><td colspan="4">
  10.    <div align="right">
  11.      <input type="reset" name="reset" /><input type="submit" name="Action" value="Submit">
  12.    </div></TD>
  13. </TR></form></Table>
  14. </body>
  15. </html>
Upload.asp
Expand|Select|Wrap|Line Numbers
  1. <%
  2.  
  3. Class FileUploader
  4.     Public  Files
  5.     Private mcolFormElem
  6.  
  7.     Private Sub Class_Initialize()
  8.         Set Files = Server.CreateObject("Scripting.Dictionary")
  9.         Set mcolFormElem = Server.CreateObject("Scripting.Dictionary")
  10.     End Sub
  11.  
  12.     Private Sub Class_Terminate()
  13.         If IsObject(Files) Then
  14.             Files.RemoveAll()
  15.             Set Files = Nothing
  16.         End If
  17.         If IsObject(mcolFormElem) Then
  18.             mcolFormElem.RemoveAll()
  19.             Set mcolFormElem = Nothing
  20.         End If
  21.     End Sub
  22.  
  23.     Public Property Get Form(sIndex)
  24.         Form = ""
  25.         If mcolFormElem.Exists(LCase(sIndex)) Then Form = mcolFormElem.Item(LCase(sIndex))
  26.     End Property
  27.  
  28.     Public Default Sub Upload()
  29.         Dim biData, sInputName
  30.         Dim nPosBegin, nPosEnd, nPos, vDataBounds, nDataBoundPos
  31.         Dim nPosFile, nPosBound
  32.  
  33.         biData = Request.BinaryRead(Request.TotalBytes)
  34.         nPosBegin = 1
  35.         nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))
  36.  
  37.         If (nPosEnd-nPosBegin) <= 0 Then Exit Sub
  38.  
  39.         vDataBounds = MidB(biData, nPosBegin, nPosEnd-nPosBegin)
  40.         nDataBoundPos = InstrB(1, biData, vDataBounds)
  41.  
  42.         Do Until nDataBoundPos = InstrB(biData, vDataBounds & CByteString("--"))
  43.  
  44.             nPos = InstrB(nDataBoundPos, biData, CByteString("Content-Disposition"))
  45.             nPos = InstrB(nPos, biData, CByteString("name="))
  46.             nPosBegin = nPos + 6
  47.             nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(34)))
  48.             sInputName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
  49.             nPosFile = InstrB(nDataBoundPos, biData, CByteString("filename="))
  50.             nPosBound = InstrB(nPosEnd, biData, vDataBounds)
  51.  
  52.             If nPosFile <> 0 And  nPosFile < nPosBound Then
  53.                 Dim oUploadFile, sFileName
  54.                 Set oUploadFile = New UploadedFile
  55.  
  56.                 nPosBegin = nPosFile + 10
  57.                 nPosEnd =  InstrB(nPosBegin, biData, CByteString(Chr(34)))
  58.                 sFileName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
  59.                 oUploadFile.FileName = Right(sFileName, Len(sFileName)-InStrRev(sFileName, "\"))
  60.  
  61.                 nPos = InstrB(nPosEnd, biData, CByteString("Content-Type:"))
  62.                 nPosBegin = nPos + 14
  63.                 nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))
  64.  
  65.                 oUploadFile.ContentType = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
  66.  
  67.                 nPosBegin = nPosEnd+4
  68.                 nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
  69.                 oUploadFile.FileData = MidB(biData, nPosBegin, nPosEnd-nPosBegin)
  70.  
  71.                 If oUploadFile.FileSize > 0 Then Files.Add LCase(sInputName), oUploadFile
  72.             Else
  73.                 nPos = InstrB(nPos, biData, CByteString(Chr(13)))
  74.                 nPosBegin = nPos + 4
  75.                 nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
  76.                 If Not mcolFormElem.Exists(LCase(sInputName)) Then mcolFormElem.Add LCase(sInputName), CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
  77.             End If
  78.  
  79.             nDataBoundPos = InstrB(nDataBoundPos + LenB(vDataBounds), biData, vDataBounds)
  80.         Loop
  81.     End Sub
  82.  
  83.     'String to byte string conversion
  84.     Private Function CByteString(sString)
  85.         Dim nIndex
  86.         For nIndex = 1 to Len(sString)
  87.            CByteString = CByteString & ChrB(AscB(Mid(sString,nIndex,1)))
  88.         Next
  89.     End Function
  90.  
  91.     'Byte string to string conversion
  92.     Private Function CWideString(bsString)
  93.         Dim nIndex
  94.         CWideString =""
  95.         For nIndex = 1 to LenB(bsString)
  96.            CWideString = CWideString & Chr(AscB(MidB(bsString,nIndex,1))) 
  97.         Next
  98.     End Function
  99. End Class
  100.  
  101. Class UploadedFile
  102.     Public ContentType
  103.     Public FileName
  104.     Public FileData
  105.  
  106.     Public Property Get FileSize()
  107.         FileSize = LenB(FileData)
  108.     End Property
  109.  
  110.     Public Sub SaveToDisk(sPath)
  111.         Dim oFS, oFile
  112.         Dim nIndex
  113.  
  114.         If sPath = "" Or FileName = "" Then Exit Sub
  115.         If Mid(sPath, Len(sPath)) <> "\" Then sPath = sPath & "\"
  116.  
  117.         Set oFS = Server.CreateObject("Scripting.FileSystemObject")
  118.         If Not oFS.FolderExists(sPath) Then Exit Sub
  119.  
  120.         Set oFile = oFS.CreateTextFile(sPath & FileName, True)
  121.  
  122.         For nIndex = 1 to LenB(FileData)
  123.             oFile.Write Chr(AscB(MidB(FileData,nIndex,1)))
  124.         Next
  125.  
  126.         oFile.Close
  127.     End Sub
  128.  
  129.     Public Sub SaveToDatabase(ByRef oField)
  130.         If LenB(FileData) = 0 Then Exit Sub
  131.  
  132.         If IsObject(oField) Then
  133.             oField.AppendChunk FileData
  134.         End If
  135.     End Sub
  136.  
  137. End Class
  138. %>
& uploadexmple.as p

Expand|Select|Wrap|Line Numbers
  1. <%@ Language=VBScript %>
  2. <%Option Explicit%>
  3. <!-- #include file="upload.asp" -->
  4. <%
  5.  
  6. 'NOTE - YOU MUST HAVE VBSCRIPT v5.0 INSTALLED ON YOUR WEB SERVER
  7. '       FOR THIS LIBRARY TO FUNCTION CORRECTLY. YOU CAN OBTAIN IT
  8. '       FREE FROM MICROSOFT WHEN YOU INSTALL INTERNET EXPLORER 5.0
  9. '       OR LATER.
  10.  
  11.  
  12. ' Create the FileUploader
  13. Dim Uploader, File, Pathhtm
  14. Set Uploader = New FileUploader
  15.  
  16. ' This starts the upload process
  17. Uploader.Upload()
  18.  
  19. '******************************************
  20. ' Use [FileUploader object].Form to access 
  21. ' additional form variables submitted with
  22. ' the file upload(s). (used below)
  23. '******************************************
  24.  
  25.  
  26. ' Check if any files were uploaded
  27. If Uploader.Files.Count = 0 Then
  28.     Response.Write "File(s) not uploaded."
  29. Else
  30.     ' Loop through the uploaded files
  31.     For Each File In Uploader.Files.Items
  32.  
  33.     File.SaveToDisk "path to save to"        
  34.  
  35.  
  36.         ' Output the file details to the browser
  37.  
  38.         Response.Write "<strong>Success!</strong><br>"
  39.         Response.Write "File Uploaded: " & File.FileName & "<br>"
  40.  
  41.     Next
  42. End If
  43.  
  44.  %>
The problem I am having is that it only randomly works. For example, today I was successful at uploading a file that is 30KB, but failed with one that is 6MB and another that is 15KB.

Is there something I am missing? Any help would be really appreciated.
Jul 30 '09 #1
0 2734

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

Similar topics

4
2769
by: dickiedyce | last post by:
Hi there. I've spent the weekend getting ever more frustrated, trying to get an upload file function working on a website. The site is hosted by a company called oneandone. They're using PHP 4.2. 3, not in safe mode. I think that the basic problem is the set-up for the temp folder, but I don't have access to the .ini settings. I'm pretty sure it's possible, because I've got MyPHPAdmin running, and
5
7826
by: Kevin Ollivier | last post by:
Hi all, I've come across a problem that has me stumped, and I thought I'd send a message to the gurus to see if this makes sense to anyone else. =) Basically, I'm trying to upload a series of files via FTP. I'm using ftplib to do it, and for each file I'm using transfercmd("STOR " + myfile) to get the socket, then uploading 4096 bytes at a time and providing status updates via a GUI interface. Finally, I close the socket, set it to...
5
5459
by: Ron Brennan | last post by:
Good afternoon. The entire task that I'm trying to achieve is to allow a user to browse and upload multiple files simultaneously, hiding the Browse button of <input> tags of type="file" and replacing it with a button of my own background color and text. The file paths I'd like displayed in a textarea and then the files uploaded at once.
13
4295
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming that this is suppossed to end up as a component for others to use, and therefore I do NOT have access to their global.cs::Session_End() how do I cleanup files that were uploaded -- but obviously left stranded when the users aborted/gave up writting...
0
2200
by: Raj | last post by:
Hello, I am planning to provide the Pause/Resume while uploading files. Our site is using both java applet and activex to do this. The list of selected files will be stored in an encrypted file using SHA256 (I have taken the code from: http://www.vbforums.com/showthread.php?s=&threadid=232284)
221
367313
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application needs to store entire files, the preferred method is to save the file onto the server’s file-system, and store the physical location of the file in your database. This is generally considered to be the easiest and fastest way to store files. ...
2
2326
by: =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?= | last post by:
jodleren escribió: I haven't found the PHP manual page where such feature is documented but a few tests have shown that this behaviour changes depending on the charset parameter of the "Content-Type" HTTP header; even if I don't set an actual HTTP header and I just use a <metatag: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> With a packet sniffer I've determined that it's not the browser who
1
726
by: =?Utf-8?B?RGFu?= | last post by:
MS won't seem to let me reply to my old post, so I created a new one. The error occurs in all browsers. It's definitely a server issue, not client. The server is not proxied in any way. I tried uploading the files on the server and experienced the same issues as I get on any other computer. Thanks in advance for your help. Dan
3
5169
by: muziburrehaman | last post by:
i am looking for code in php to upload the 1 gb files. any one can please help me by sending the code....
0
8057
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
8491
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8142
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
6813
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...
1
6010
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...
0
5475
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
3959
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
4022
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2472
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

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.