Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Upload script, how to upload more than 100k?

Status
Not open for further replies.

lslapiko

Programmer
Nov 17, 2002
1
US
I am using the following code to let users upload files. Downloaded it from the web somewhere. How can I modify this script to get rid of the 100k limit?

Script 1
<%
Option Explicit
%>
<!--#include file=&quot;modMimeFunctions.asp&quot; -->

<!-- #include file = ../../inc/adovbs.inc -->
<!-- #include file = ../../inc/globals.inc -->

<html>
<head>
<title>ALEA: Paper Upload Confirmation</title>
<style>
<!-- #include file = ../../inc/style.inc -->
</style>
<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
<!-- #include file = ../../inc/level3nav_preload.inc -->
</script>
</head>

<body bgcolor=&quot;#ffffff&quot; background=&quot;../../images/bg.gif&quot; topmargin=&quot;0&quot; leftmargin=&quot;0&quot;>

<table width=&quot;100%&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; border=&quot;0&quot;>
<tr>
<td width=&quot;166&quot; align=&quot;right&quot; valign=&quot;top&quot; rowspan=&quot;500&quot;>
<table width=&quot;166&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>
<tr>
<td bgcolor=&quot;#ffffff&quot;><a href=&quot; src=&quot;../../images/logo.gif&quot; border=&quot;0&quot;></a></td>
</tr>
<!-- #include file = ../../inc/level3nav.inc -->
</table>
</td>
<td width=&quot;100%&quot; rowspan=&quot;500&quot; valign=&quot;top&quot;>
<table width=&quot;100%&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; bordercolor=&quot;orange&quot;>
<tr>
<td width=&quot;5%&quot; rowspan=&quot;500&quot;> </td>
<td width=&quot;90%&quot; height=&quot;150&quot; class=&quot;title&quot; valign=&quot;bottom&quot;>Confirmation of Paper Submission</td>
<td width=&quot;5%&quot; rowspan=&quot;500&quot;> </td>
</tr>
<tr>
<td width=&quot;90%&quot;>
<table border=&quot;0&quot; cellpadding=&quot;2&quot; cellspacing=&quot;0&quot;>
<tr>
<td colspan=&quot;2&quot;> </td>
</tr>
<tr>
<td class=&quot;smalltext&quot; colspan=&quot;2&quot;><p>The following paper has been submitted for the 2003 ALEA Annual Meeting.</p></td>
</tr>
<tr>
<td> </td>
</tr>
<td colspan=&quot;2&quot; class=&quot;smalltext&quot;>
<%


dim author
author = Session(&quot;author&quot;)
dim title
title = Session(&quot;title&quot;)
dim area
area = Session(&quot;area&quot;)
dim comments
comments = Session(&quot;comments&quot;)
dim db_ID
db_ID = Session(&quot;db_ID&quot;)
dim submitted_by

dim conn
set conn = server.CreateObject(&quot;ADODB.Connection&quot;)
conn.Open cALEA, cDB_USERNAME, cDB_PASSWORD

dim rs
dim SQL

set rs = Server.CreateObject(&quot;ADODB.RecordSet&quot;)
SQL = &quot;SELECT * FROM person WHERE db_ID = &quot; & db_ID
rs.open SQL, conn, adOpenKeySet, adLockPessimistic, adCmdText

submitted_by = rs.Fields(&quot;f_name&quot;)
submitted_by = submitted_by & &quot; &quot;
submitted_by = submitted_by & rs.Fields(&quot;l_name&quot;)

rs.Close
set rs = nothing

response.write(&quot;<p><span class='boldtext'>Title:</span> &quot; & title & &quot;</p>&quot;)
response.write(&quot;<p><span class='boldtext'>Author(s):</span> &quot; & author & &quot;</p>&quot;)
response.write(&quot;<p><span class='boldtext'>Submitted by:</span> &quot; & submitted_by & &quot;</p>&quot;)
response.write(&quot;<p><span class='boldtext'>Comments:</span> &quot; & comments & &quot;</p>&quot;)
response.write(&quot;<p><span class='boldtext'>Subject area(s):</span><br>&quot;)

dim areaArray
areaArray = Split(area, &quot;, &quot;)

'dim conn
'set conn = server.CreateObject(&quot;ADODB.Connection&quot;)
'conn.Open cALEA, cDB_USERNAME, cDB_PASSWORD

dim strArea_name
dim i
for i = LBound(areaArray) to UBound(areaArray)
set rs = Server.CreateObject(&quot;ADODB.RecordSet&quot;)
SQL = &quot;SELECT * FROM area WHERE area_ID = &quot; & areaArray(i)
rs.open SQL, conn, adOpenKeySet, adLockPessimistic, adCmdText
strArea_name = rs.Fields(&quot;area&quot;)
response.write(strArea_name & &quot;<br>&quot;)
rs.close
set rs = nothing
next

conn.close
set conn = nothing

response.write(&quot;</p>&quot;)

Response.Write &quot;<p>Upload started: &quot; & Now & &quot;</p>&quot;

Dim lngBytesReceived, arrFiles, lngItemIndex
Dim strActualFileOrValue, strSourcePath, strSaveName

Dim strName

lngBytesReceived = Request.TotalBytes

If lngBytesReceived > 102400 Then

Response.Write(&quot;<DIV ALIGN=&quot;&quot;CENTER&quot;&quot;><B>Sorry, your request cannot be completed because:<BR><BR>Maximum allowed file size for both files (combined) is 100KB. Your request: &quot; & CLng(lngBytesReceived / 1024) & &quot;KB</DIV>&quot;)
Response.End
End If

If lngBytesReceived > 0 Then 'Data has been received
%>
<!-- <DIV ALIGN=&quot;CENTER&quot;><IMG SRC=&quot;images/processing.gif&quot;><BR>Files are uploading... Please wait...</DIV> -->
<FORM NAME=FORM1>
<%
'Put files into a String Array
arrFiles = GetMimeArray()

'Loop for every file in the Array
For lngItemIndex = 0 To UBound(arrFiles)

If GetMimeHeader(arrFiles(lngItemIndex)) = &quot;&quot; Then 'No header found

Response.Write lngItemIndex & &quot;: No header found<BR>&quot;

Else 'Header found

If GetMimeContentDisposition(arrFiles(lngItemIndex)) <> &quot;form-data&quot; Then 'No Content-Disposition found

Response.Write &quot;<b>=== ERROR: Unknown data</b><BR>&quot;

Else 'Content-Disposition found

'Parse actual file
strActualFileOrValue = GetMimeValue(arrFiles(lngItemIndex))

If GetMimeContentType(arrFiles(lngItemIndex)) = &quot;&quot; Or GetMimeFilename(arrFiles(lngItemIndex)) = &quot;&quot; Then 'No Content-type Or filename found

strName = GetMimeName(arrFiles(lngItemIndex))

'Write form name and value
Response.Write(&quot;<INPUT TYPE=&quot;&quot;HIDDEN&quot;&quot; NAME=&quot;&quot;&quot; & strName & &quot;&quot;&quot; VALUE=&quot;&quot;&quot; & strActualFileOrValue & &quot;&quot;&quot;>&quot; & vbCrLf)

'Response.Write &quot;<b>=== ERROR: Not a file</b><BR>&quot;
'Response.Write &quot;--- Data submitted: <b>&quot; & strActualFileOrValue & &quot;</b>&quot;
'Response.Write &quot; (Length=&quot; & Len(strActualFileOrValue) & &quot;)<BR>&quot;

Else 'Content-type And filename found

If GetMimeName(arrFiles(lngItemIndex)) = &quot;&quot; Then 'Input has no name

Response.Write &quot;<b>=== ERROR: Input name not found</b><BR>&quot;

Else 'Input has a name

strSourcePath = GetMimeFilename(arrFiles(lngItemIndex))

If strSourcePath = &quot;&quot; Then 'No filename found

Response.Write &quot;<b>=== ERROR: Source path not found</b><BR>&quot;

Else 'Filename found

strSaveName = GetFilenameFromPath(strSourcePath)

If strSaveName = &quot;&quot; Then 'Save name not found

Response.Write &quot;Error: Save name not found: &quot; & strSourcePath & &quot;<BR>&quot;

Else 'Save name found, everything's OK

Response.Write(&quot;<INPUT TYPE=&quot;&quot;HIDDEN&quot;&quot; NAME=&quot;&quot;&quot; & GetMimeName(arrFiles(lngItemIndex)) & &quot;&quot;&quot; VALUE=&quot;&quot;&quot; & strSaveName & &quot;&quot;&quot;>&quot; & vbCrLf)

Call WriteFile(strActualFileOrValue, Server.MapPath(&quot;uploaded\&quot; & strSaveName))
End If
End If
End If
End If
End If
End If
Next
End If

'All done, now redirect
Response.Write &quot;<p>Upload complete: &quot; & Now & &quot;</p>&quot;
%>

</td>
</tr>
<tr>
<td colspan=&quot;2&quot;> </td>
</tr>
<tr>
<td colspan=&quot;2&quot;>
<input type=&quot;button&quot; name=&quot;another&quot; value=&quot;Submit Another&quot; onclick=&quot;document.location='default.asp';&quot;>  
<input type=&quot;button&quot; name=&quot;finish&quot; value=&quot;Finish&quot; onclick=&quot;document.location='../default.asp';&quot;>
</td>
</tr>
</FORM>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>

</body>
</html>
<SCRIPT>
document.forms[0].action = &quot;TargetPage.asp&quot;
document.forms[0].method = &quot;POST&quot;
//document.forms[0].submit()
</SCRIPT>

Script 2:
<%
'MIME Parsing Functions Module
'Author: Luis Cantero
'© 2002 L.C. Enterprises
''Updated: 10/OCT/2002


'PURPOSE: Returns the HEADER of a Mime entry
'INPUT: String: Mime entry
'OUTPUT: String: Found header | Empty
Function GetMimeHeader(strMime)

Dim intDataStart, strHeader

'Find header boundary
intDataStart = InStr(strMime, vbCrLf & vbCrLf)
If intDataStart > 0 Then 'Header boundary found
'Parse header and return
GetMimeHeader = Left(strMime, intDataStart - 1)
End If

End Function

'PURPOSE: Returns an array containing the received multipart data in Mime format
'OUTPUT: String Array | Empty
Function GetMimeArray()

Dim intI, strBytes, strSignature, strCompleteData

'Get binary data
strBytes = Request.BinaryRead(Request.TotalBytes)

For intI = 1 To LenB(strBytes) 'Convert binary data to a String
strCompleteData = strCompleteData & Chr(AscB(MidB(strBytes, intI, 1)))
Next

'Parse Signature (file separator)
strSignature = Left(strCompleteData, InStr(strCompleteData, vbCrLf) + 1)

strCompleteData = Mid(strCompleteData, InStr(strCompleteData, vbCrLf) + 2, Len(strCompleteData) - 2 - 2 * Len(strSignature))

'Put files into a String Array and return
GetMimeArray = Split(strCompleteData, strSignature)

End Function

'PURPOSE: Returns the &quot;Content-Disposition&quot; of a Mime entry
'INPUT: String: Mime entry
'OUTPUT: String: Found content-disposition | Empty
Function GetMimeContentDisposition(strMime)

GetMimeContentDisposition = GetMimeValueByCoord(strMime, &quot;Content-Disposition:&quot;, &quot;;&quot;)

End Function

'PURPOSE: Returns the &quot;Content-Type&quot; of a Mime entry
'INPUT: String: Mime entry
'OUTPUT: String: Found content-type | Empty
Function GetMimeContentType(strMime)

GetMimeContentType = GetMimeValueByCoord(strMime, &quot;Content-Type:&quot;, vbCrLf)

End Function

'PURPOSE: Returns the &quot;filename&quot; of a Mime entry
'INPUT: String: Mime entry
'OUTPUT: String: Found filename | Empty
Function GetMimeFilename(strMime)

GetMimeFilename = GetMimeValueByCoord(strMime, &quot;filename=&quot;&quot;&quot;, &quot;&quot;&quot;&quot;)

End Function

'PURPOSE: Returns the &quot;name&quot; of a Mime entry
'INPUT: String: Mime entry
'OUTPUT: String: Found name | Empty
Function GetMimeName(strMime)

GetMimeName = GetMimeValueByCoord(strMime, &quot;name=&quot;&quot;&quot;, &quot;&quot;&quot;&quot;)

End Function

'PURPOSE: Returns the value of an ENTRY of a Mime entry
'INPUT: String: Mime entry
'OUTPUT: String: Found value | Empty
Function GetMimeValue(strMime)

Dim intBeg

'Search for left boundary
intBeg = InStr(1, strMime, vbCrLf & vbCrLf) + Len(vbCrLf & vbCrLf)

If intBeg > 0 Then
'Return found value
GetMimeValue = Mid(strMime, intBeg, Len(strMime) - intBeg - 1)
End If

End Function

'PURPOSE: Returns the value of a VARIABLE of a Mime entry
'INPUT: String: Mime entry, String: Left and right bounds
'OUTPUT: String: Found value | Empty
Function GetMimeValueByCoord(strMime, strLeftBound, strRightBound)

Dim intBeg, intEnd, strHeader

'Get header
strHeader = GetMimeHeader(strMime)

'Search for value name in header
intBeg = InStr(1, strHeader, strLeftBound)

If intBeg > 0 Then 'Value name found in header, parse value
intBeg = intBeg + Len(strLeftBound)
intEnd = InStr(intBeg, strMime, strRightBound)

If intEnd = 0 Then intEnd = Len(strMime)

'Return found value
GetMimeValueByCoord = Trim(Mid(strMime, intBeg, intEnd - intBeg))
End If

End Function

'PURPOSE: Returns the value of an ENTRY in the Mime array, according to it's NAME
'INPUT: Array: Mime array, String: Name of the value to be retrieved
'OUTPUT: String: Found value | Empty
Function GetMimeValueByName(arrMime, strValueName)

Dim intI, intBeg, strHeader

'Search all items of array
For intI = 0 To UBound(arrMime)

'Get header
strHeader = GetMimeHeader(arrMime(intI))
If strHeader <> &quot;&quot; Then 'Header found
'Search for value name in header
intBeg = InStr(1, strHeader, &quot;name=&quot;&quot;&quot; & strValueName & &quot;&quot;&quot;&quot;)
If intBeg > 0 Then 'Value name found in header, parse value
intBeg = intBeg + Len(&quot;name=&quot;&quot;&quot; & strValueName & &quot;&quot;&quot;&quot;) + Len(vbCrLf & vbCrLf)

'Return found value
GetMimeValueByName = Mid(arrMime(intI), intBeg, Len(arrMime(intI)) - intBeg - 1)
Exit For
End If
End If
Next

End Function

'PURPOSE: Extracts the name of a file from its path
'INPUT: String: Path
'OUTPUT: String: Name
Function GetFilenameFromPath(strPath)

Dim intI

intI = InStrRev(strPath, &quot;\&quot;)
If intI > 0 Then
GetFilenameFromPath = Mid(strPath, intI + 1)
Else
GetFilenameFromPath = strPath
End If

End Function

'PURPOSE: Saves a file using the FileSystemObject
'INPUT: String: files's contents, String: save path
Sub WriteFile(strFileData, strSavePath)

Dim objFSO, objTextStream

If Len(strFileData) = 0 Then Exit Sub

'Create objects
Set objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set objTextStream = objFSO.CreateTextFile(strSavePath, True, False)

'Write file and close it
objTextStream.Write strFileData
objTextStream.Close

'Delete objects
Set objTextStream = Nothing
Set objFSO = Nothing

End Sub

'PURPOSE: Deletes a file using the FileSystemObject
'INPUT: String: files's path
Sub DeleteFile(strPath)

Dim objFSO, tmpFileHandle

'Create object
Set objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)

'Delete zoom image
If objFSO.FileExists(strPath) Then
Set tmpFileHandle = objFSO.GetFile(strPath)
tmpFileHandle.Delete
End If

'Delete objects
Set tmpFileHandle = Nothing
Set objFSO = Nothing

End Sub

'PURPOSE: Generates a &quot;Unique Random Filename&quot; to save uploaded files
'INPUT: String: Name of uploaded file
'OUTPUT: String: Unique random filename in this format: Date_RandomNumber.EXT
'NOTES: RandomNumber = Round(RND * 1000000), Extension is kept
Function GenerateRandomName(strFileName)

Dim strDate

'Remove illegal characters for a filename
strDate = Replace(Date, &quot;/&quot;, &quot;.&quot;)

Randomize

'Return
GenerateRandomName = strDate & &quot;_&quot; & CStr(Round(RND * 1000000)) & Right(strFileName, 4) 'Date_RandomNumber.EXT

End Function
%>
 
If you change this line &quot;
Code:
If lngBytesReceived > 102400 Then
&quot; by raising the comparision value, you'll get rid of the message for over 100K files. Thus, this message may be here for technical reasons that should crash your page if Upload is > 100Kb. Try and tell me. Water is not bad as long as it stays out human body ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top