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 - <?xml version="1.0" encoding="iso-8859-1"?>
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-
<head>
-
</head><body>
-
<table width="500" border="1" frame="box" rules="none" align="center" cellpadding="0" cellspacing="0">
-
<FORM name="form" ENCTYPE="multipart/form-data" METHOD="POST" ACTION="uploadexmple.asp">
-
<tr><TD colspan="4"><strong>Upload syllabus (one file)</strong></td>
-
</tr><tr><td colspan="4"><INPUT TYPE=FILE SIZE=50 NAME="FILE1"></td></tr><TR><td colspan="4">
-
<div align="right">
-
<input type="reset" name="reset" /><input type="submit" name="Action" value="Submit">
-
</div></TD>
-
</TR></form></Table>
-
</body>
-
</html>
Upload.asp -
<%
-
-
Class FileUploader
-
Public Files
-
Private mcolFormElem
-
-
Private Sub Class_Initialize()
-
Set Files = Server.CreateObject("Scripting.Dictionary")
-
Set mcolFormElem = Server.CreateObject("Scripting.Dictionary")
-
End Sub
-
-
Private Sub Class_Terminate()
-
If IsObject(Files) Then
-
Files.RemoveAll()
-
Set Files = Nothing
-
End If
-
If IsObject(mcolFormElem) Then
-
mcolFormElem.RemoveAll()
-
Set mcolFormElem = Nothing
-
End If
-
End Sub
-
-
Public Property Get Form(sIndex)
-
Form = ""
-
If mcolFormElem.Exists(LCase(sIndex)) Then Form = mcolFormElem.Item(LCase(sIndex))
-
End Property
-
-
Public Default Sub Upload()
-
Dim biData, sInputName
-
Dim nPosBegin, nPosEnd, nPos, vDataBounds, nDataBoundPos
-
Dim nPosFile, nPosBound
-
-
biData = Request.BinaryRead(Request.TotalBytes)
-
nPosBegin = 1
-
nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))
-
-
If (nPosEnd-nPosBegin) <= 0 Then Exit Sub
-
-
vDataBounds = MidB(biData, nPosBegin, nPosEnd-nPosBegin)
-
nDataBoundPos = InstrB(1, biData, vDataBounds)
-
-
Do Until nDataBoundPos = InstrB(biData, vDataBounds & CByteString("--"))
-
-
nPos = InstrB(nDataBoundPos, biData, CByteString("Content-Disposition"))
-
nPos = InstrB(nPos, biData, CByteString("name="))
-
nPosBegin = nPos + 6
-
nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(34)))
-
sInputName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
-
nPosFile = InstrB(nDataBoundPos, biData, CByteString("filename="))
-
nPosBound = InstrB(nPosEnd, biData, vDataBounds)
-
-
If nPosFile <> 0 And nPosFile < nPosBound Then
-
Dim oUploadFile, sFileName
-
Set oUploadFile = New UploadedFile
-
-
nPosBegin = nPosFile + 10
-
nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(34)))
-
sFileName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
-
oUploadFile.FileName = Right(sFileName, Len(sFileName)-InStrRev(sFileName, "\"))
-
-
nPos = InstrB(nPosEnd, biData, CByteString("Content-Type:"))
-
nPosBegin = nPos + 14
-
nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))
-
-
oUploadFile.ContentType = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
-
-
nPosBegin = nPosEnd+4
-
nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
-
oUploadFile.FileData = MidB(biData, nPosBegin, nPosEnd-nPosBegin)
-
-
If oUploadFile.FileSize > 0 Then Files.Add LCase(sInputName), oUploadFile
-
Else
-
nPos = InstrB(nPos, biData, CByteString(Chr(13)))
-
nPosBegin = nPos + 4
-
nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
-
If Not mcolFormElem.Exists(LCase(sInputName)) Then mcolFormElem.Add LCase(sInputName), CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
-
End If
-
-
nDataBoundPos = InstrB(nDataBoundPos + LenB(vDataBounds), biData, vDataBounds)
-
Loop
-
End Sub
-
-
'String to byte string conversion
-
Private Function CByteString(sString)
-
Dim nIndex
-
For nIndex = 1 to Len(sString)
-
CByteString = CByteString & ChrB(AscB(Mid(sString,nIndex,1)))
-
Next
-
End Function
-
-
'Byte string to string conversion
-
Private Function CWideString(bsString)
-
Dim nIndex
-
CWideString =""
-
For nIndex = 1 to LenB(bsString)
-
CWideString = CWideString & Chr(AscB(MidB(bsString,nIndex,1)))
-
Next
-
End Function
-
End Class
-
-
Class UploadedFile
-
Public ContentType
-
Public FileName
-
Public FileData
-
-
Public Property Get FileSize()
-
FileSize = LenB(FileData)
-
End Property
-
-
Public Sub SaveToDisk(sPath)
-
Dim oFS, oFile
-
Dim nIndex
-
-
If sPath = "" Or FileName = "" Then Exit Sub
-
If Mid(sPath, Len(sPath)) <> "\" Then sPath = sPath & "\"
-
-
Set oFS = Server.CreateObject("Scripting.FileSystemObject")
-
If Not oFS.FolderExists(sPath) Then Exit Sub
-
-
Set oFile = oFS.CreateTextFile(sPath & FileName, True)
-
-
For nIndex = 1 to LenB(FileData)
-
oFile.Write Chr(AscB(MidB(FileData,nIndex,1)))
-
Next
-
-
oFile.Close
-
End Sub
-
-
Public Sub SaveToDatabase(ByRef oField)
-
If LenB(FileData) = 0 Then Exit Sub
-
-
If IsObject(oField) Then
-
oField.AppendChunk FileData
-
End If
-
End Sub
-
-
End Class
-
%>
& uploadexmple.as p - <%@ Language=VBScript %>
-
<%Option Explicit%>
-
<!-- #include file="upload.asp" -->
-
<%
-
-
'NOTE - YOU MUST HAVE VBSCRIPT v5.0 INSTALLED ON YOUR WEB SERVER
-
' FOR THIS LIBRARY TO FUNCTION CORRECTLY. YOU CAN OBTAIN IT
-
' FREE FROM MICROSOFT WHEN YOU INSTALL INTERNET EXPLORER 5.0
-
' OR LATER.
-
-
-
' Create the FileUploader
-
Dim Uploader, File, Pathhtm
-
Set Uploader = New FileUploader
-
-
' This starts the upload process
-
Uploader.Upload()
-
-
'******************************************
-
' Use [FileUploader object].Form to access
-
' additional form variables submitted with
-
' the file upload(s). (used below)
-
'******************************************
-
-
-
' Check if any files were uploaded
-
If Uploader.Files.Count = 0 Then
-
Response.Write "File(s) not uploaded."
-
Else
-
' Loop through the uploaded files
-
For Each File In Uploader.Files.Items
-
-
File.SaveToDisk "path to save to"
-
-
-
' Output the file details to the browser
-
-
Response.Write "<strong>Success!</strong><br>"
-
Response.Write "File Uploaded: " & File.FileName & "<br>"
-
-
Next
-
End If
-
-
%>
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.
0 2734 Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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...
|
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.
|
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...
|
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)
| |
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.
...
|
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
|
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
|
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....
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |