Hello,
I got the following scripts to upload files to my directories
I call insert.htm
Browse for a file, then click 'submit'
It works for small files, and for a small .mdb (access file)
But for any larger file, it quits and give me 'page not found'
Is there some kind of timeout I can set?
Note: insert.htm calls insert.asp, call load.asp
Thanks:
Insert.asp:
<!-- insert.htm -->
<html>
<head>
<title>File Uploading with ASP</title>
<style>
body, input { font-family:verdana, arial; font-size:10pt; }
</style>
</head>
<body>
<p align="center">
<b>File Uploading with ASP</b><br>
<a href="show.asp" >To see uploaded data click here</a>
</p>
<table border="0" align="center">
<tr>
<form method="POST" enctype="multip art/form-data" action="Insert. asp">
<td>Name :</td><td>
<input type="text" name="name" size="40"></td></tr>
<td>File :</td><td>
<input type="file" name="file" size="40"></td></tr>
<td> </td><td>
<input type="submit" value="Submit"> </td></tr>
</form>
</tr>
</table>
</body>
</html>
insert.asp:
<% ' Insert.asp %>
<!--#include file="Loader.as p"-->
<%
Response.Buffer = True
' load object
Dim load
Set load = new Loader
' calling initialize method
load.initialize
response.write "<br>hi1122 "
' File binary data
Dim fileData
fileData = load.getFileDat a("file")
' File name
Dim fileName
fileName = LCase(load.getF ileName("file") )
' File path
Dim filePath
filePath = load.getFilePat h("file")
' File path complete
Dim filePathComplet e
filePathComplet e = load.getFilePat hComplete("file ")
' File size
Dim fileSize
fileSize = load.getFileSiz e("file")
' File size translated
Dim fileSizeTransla ted
fileSizeTransla ted = load.getFileSiz eTranslated("fi le")
' Content Type
Dim contentType
contentType = load.getContent Type("file")
' No. of Form elements
Dim countElements
countElements = load.Count
' Value of text input field "name"
Dim nameInput
nameInput = load.getValue(" name")
' Path where file will be uploaded
Dim pathToFile
' pathToFile = Server.mapPath( "uploaded/") & "\" & fileName
pathToFile = Server.mapPath( "businessse arch/") & "\" & fileName
' Uploading file data
response.write "<br>hi1122 33"
response.write "<br> " & pathtofile
'response.end
Dim fileUploaded
fileUploaded = load.saveToFile ("file", pathToFile)
'response.write "<br>hi11223344 4"
'response.end
' destroying load object
Set load = Nothing
%>
<html>
<head>
<title>File Uploading with ASP</title>
<style>
body, input, td { font-family:verdana, arial; font-size:10pt; }
</style>
</head>
<body>
<p align="center">
<b>File Uploading with ASP</b><br>
<a href="show.asp" >To see uploaded files click here</a>
</p>
<table width="700" border="1" align="center">
<tr>
<td>File Name</td><td><%= fileName %></td>
</tr><tr>
<td>File Path</td><td><%= filePath %></td>
</tr><tr>
<td>File Path Complete</td><td><%= filePathComplet e %></td>
</tr><tr>
<td>File Size</td><td><%= fileSize %></td>
</tr><tr>
<td>File Size Translated</td><td><%= fileSizeTransla ted %></td>
</tr><tr>
<td>Content Type</td><td><%= contentType %></td>
</tr><tr>
<td>No. of Form Elements</td><td><%= countElements %></td>
</tr><tr>
<td>Name</td><td><%= nameInput %></td>
</tr>
</table><br><br>
<p style="padding-left:220;">
<%
If fileUploaded = True Then
Response.Write fileName & " data uploaded..."
Else
Response.Write "<font color=""red"">F ile could not be uploaded..."
Response.Write "</font>"
Response.Write "<br>Please select a file before hitting the
'Submit'"
Response.Write " button."
End If
%>
</p>
<br>
<table border="0" align="center">
<tr>
<form method="POST" enctype="multip art/form-data" action="Insert. asp">
<td>Name :</td><td>
<input type="text" name="name" size="40" value="<%= nameInput %>">
</td></tr>
<td>File :</td><td>
<input type="file" name="file" size="40"></td></tr>
<td> </td><td>
<input type="submit" value="Submit"> </td></tr>
</form>
</tr>
</table>
</body>
</html>
loader.asp:
<%
' -- Loader.asp --
' -- version 1.5.2
' -- last updated 12/5/2002
'
' Faisal Khan
' fa****@stardeve loper.com
' www.stardeveloper.com
' Class for handling binary uploads
Class Loader
Private dict
Private Sub Class_Initializ e
Set dict = Server.CreateOb ject("Scripting .Dictionary")
End Sub
Private Sub Class_Terminate
If IsObject(intDic t) Then
intDict.RemoveA ll
Set intDict = Nothing
End If
If IsObject(dict) Then
dict.RemoveAll
Set dict = Nothing
End If
End Sub
Public Property Get Count
Count = dict.Count
End Property
Public Sub Initialize
If Request.TotalBy tes > 0 Then
Dim binData
binData = Request.BinaryR ead(Request.Tot alBytes)
getData binData
End If
End Sub
Public Function getFileData(nam e)
If dict.Exists(nam e) Then
getFileData = dict(name).Item ("Value")
Else
getFileData = ""
End If
End Function
Public Function getValue(name)
Dim gv
If dict.Exists(nam e) Then
gv = CStr(dict(name) .Item("Value"))
gv = Left(gv,Len(gv)-2)
getValue = gv
Else
getValue = ""
End If
End Function
Public Function saveToFile(name , path)
If dict.Exists(nam e) Then
Dim temp
temp = dict(name).Item ("Value")
Dim fso
Set fso = Server.CreateOb ject("Scripting .FileSystemObje ct")
Dim file
Set file = fso.CreateTextF ile(path)
For tPoint = 1 to LenB(temp)
file.Write Chr(AscB(MidB(t emp,tPoint,1)))
Next
file.Close
saveToFile = True
Else
saveToFile = False
End If
End Function
Public Function getFileName(nam e)
If dict.Exists(nam e) Then
Dim temp, tempPos
temp = dict(name).Item ("FileName")
tempPos = 1 + InStrRev(temp, "\")
getFileName = Mid(temp, tempPos)
Else
getFileName = ""
End If
End Function
Public Function getFilePath(nam e)
If dict.Exists(nam e) Then
Dim temp, tempPos
temp = dict(name).Item ("FileName")
tempPos = InStrRev(temp, "\")
getFilePath = Mid(temp, 1, tempPos)
Else
getFilePath = ""
End If
End Function
Public Function getFilePathComp lete(name)
If dict.Exists(nam e) Then
getFilePathComp lete = dict(name).Item ("FileName")
Else
getFilePathComp lete = ""
End If
End Function
Public Function getFileSize(nam e)
If dict.Exists(nam e) Then
getFileSize = LenB(dict(name) .Item("Value"))
Else
getFileSize = 0
End If
End Function
Public Function getFileSizeTran slated(name)
If dict.Exists(nam e) Then
temp = LenB(dict(name) .Item("Value"))
If temp <= 1024 Then
getFileSizeTran slated = temp & " bytes"
Else
temp = FormatNumber((t emp / 1024), 2)
getFileSizeTran slated = temp & " kilobytes"
End If
Else
getFileSizeTran slated = ""
End If
End Function
Public Function getContentType( name)
If dict.Exists(nam e) Then
getContentType = dict(name).Item ("ContentTyp e")
Else
getContentType = ""
End If
End Function
Private Sub getData(rawData )
Dim separator
separator = MidB(rawData, 1, InstrB(1, rawData, ChrB(13)) - 1)
Dim lenSeparator
lenSeparator = LenB(separator)
Dim currentPos
currentPos = 1
Dim inStrByte
inStrByte = 1
Dim value, mValue
Dim tempValue
tempValue = ""
While inStrByte > 0
inStrByte = InStrB(currentP os, rawData, separator)
mValue = inStrByte - currentPos
If mValue > 1 Then
value = MidB(rawData, currentPos, mValue)
Dim begPos, endPos, midValue, nValue
Dim intDict
Set intDict = Server.CreateOb ject("Scripting .Dictionary")
begPos = 1 + InStrB(1, value, ChrB(34))
endPos = InStrB(begPos + 1, value, ChrB(34))
nValue = endPos
Dim nameN
nameN = MidB(value, begPos, endPos - begPos)
Dim nameValue, isValid
isValid = True
If InStrB(1, value, stringToByte("C ontent-Type")) > 1 Then
begPos = 1 + InStrB(endPos + 1, value, ChrB(34))
endPos = InStrB(begPos + 1, value, ChrB(34))
If endPos = 0 Then
endPos = begPos + 1
isValid = False
End If
midValue = MidB(value, begPos, endPos - begPos)
intDict.Add "FileName", trim(byteToStri ng(midValue))
begPos = 14 + InStrB(endPos + 1, value,
stringToByte("C ontent-Type:"))
endPos = InStrB(begPos, value, ChrB(13))
midValue = MidB(value, begPos, endPos - begPos)
intDict.Add "ContentTyp e", trim(byteToStri ng(midValue))
begPos = endPos + 4
endPos = LenB(value)
nameValue = MidB(value, begPos, ((endPos - begPos) - 1))
Else
nameValue = trim(byteToStri ng(MidB(value, nValue + 5)))
End If
If isValid = True Then
intDict.Add "Value", nameValue
intDict.Add "Name", nameN
dict.Add byteToString(na meN), intDict
End If
End If
currentPos = lenSeparator + inStrByte
Wend
End Sub
End Class
Private Function stringToByte(to Conv)
Dim tempChar
For i = 1 to Len(toConv)
tempChar = Mid(toConv, i, 1)
stringToByte = stringToByte & chrB(AscB(tempC har))
Next
End Function
Private Function byteToString(to Conv)
For i = 1 to LenB(toConv)
byteToString = byteToString & Chr(AscB(MidB(t oConv,i,1)))
Next
End Function
%>