Print Page | Close Window

Limiting the size of a folder

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=1623
Printed Date: 29 March 2026 at 5:16am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Limiting the size of a folder
Posted By: zaboss
Subject: Limiting the size of a folder
Date Posted: 05 April 2003 at 8:19am

Well, I have a uploading script that, what else, uploads files to the server. What I want is to limit the size of the files that are uploaded (in the first place) and set a quota for the whole folder, let's say 1MB. That is, the user is allow to upload maximum 1MB in his folder, in files no large than 100.000Kb, and only .zip files. Here is the code that needs adjustment:

%
response.buffer=true
Func = Request("Func")

if isempty(Func) Then
Func = 1
End if

Select Case Func
Case 1
'You do not need to use this form to send your files.
'However you should not give your submit button a NAME or ID.
%>
<H2>Please Select a picture To upload.</H1>
<FORM ENCTYPE="multipart/form-data" ACTION="generic_UploadServer.asp?func=2" METHOD=POST id=form1 name=form1>
<TABLE>
      <TR><TD>Type In the full path and name of the file To upload.</TD></TR>
      <TR><TD>-or-</TD></TR>
      <TR><TD>Hit the [Browse] button to find the file on your computer.<BR><BR></TD></TR>
      <TR><TD>Then hit the [Upload] button.<BR><BR></TD></TR>
      <TR><TD><STRONG>File Name...</STRONG></TD></TR>
      <TR><TD><INPUT NAME=File1 SIZE=30 TYPE=file><BR></TD></TR>
      <TR><TD><INPUT NAME=File2 SIZE=30 TYPE=file><BR></TD></TR>
      <TR><TD><INPUT NAME=File3 SIZE=30 TYPE=file><BR></TD></TR>
      <TR><TD align=left><INPUT type="submit" value="Upload File"><BR><BR></TD></TR>
      <TR><TD>NOTE: Please be patient, you will not receive any notification until the file is completely transferred.<BR><BR></TD></TR>
  </TABLE>
<%
Case 2
ForWriting = 2
  adLongVarChar = 201
  lngNumberUploaded = 0

'Get binary data from form
  noBytes = Request.TotalBytes
  binData = Request.BinaryRead (noBytes)
'convery the binary data to a string
  Set RST = CreateObject("ADODB.Recordset")
  LenBinary = LenB(binData)

  if LenBinary > 0 Then
      RST.Fields.Append "myBinary", adLongVarChar, LenBinary
      RST.Open
          RST.AddNew
              RST("myBinary").AppendChunk BinData
          RST.Update
      strDataWhole = RST("myBinary")
  End if

'get the boundry indicator
strBoundry = Request.ServerVariables ("HTTP_CONTENT_TYPE")
lngBoundryPos = instr(1,strBoundry,"boundary=") + 8
strBoundry = "--" & right(strBoundry,len(strBoundry)-lngBoundryPos)
'Get first file boundry positions.
lngCurrentBegin = instr(1,strDataWhole,strBoundry)
lngCurrentEnd = instr(lngCurrentBegin + 1,strDataWhole,strBoundry) - 1
   
Do While lngCurrentEnd > 0
'Get the data between current boundry and remove it from the whole.
strData = mid(strDataWhole,lngCurrentBegin, lngCurrentEnd - lngCurrentBegin)
strDataWhole = replace(strDataWhole,strData,"")

'Get the full path of the current file.
  lngBeginFileName = instr(1,strdata,"filename=") + 10
  lngEndFileName = instr(lngBeginFileName,strData,chr(34))
'Make sure they selected at least one file.
  if lngBeginFileName = lngEndFileName and lngNumberUploaded = 0 Then
          Response.Write "<H2> The following Error occured.</H2>"
          Response.Write "You must Select at least one file To upload"
          Response.Write "<BR><BR>Hit the back button, make the needed corrections and resubmit your information."
          Response.Write "<BR><BR><INPUT type='button' onclick='history.go(-1)' value='<< Back' id='button'1 name='button'1>"
          Response.End
  End if
'There could be one or more empty file boxes.
  if lngBeginFileName <> lngEndFileName Then
      strFilename = mid(strData,lngBeginFileName,lngEndFileName - lngBeginFileName)

'Loose the path information and keep just the file name.
      tmpLng = instr(1,strFilename,"\")
         
      Do While tmpLng > 0
          PrevPos = tmpLng
          tmpLng = instr(PrevPos + 1,strFilename,"\")
      Loop

      FileName = right(strFilename,len(strFileName) - PrevPos)
'Get the begining position of the file data sent.
'if the file type is registered with the browser then there will be a Content-Type
      lngCT = instr(1,strData,"Content-Type:")

      if lngCT > 0 Then
          lngBeginPos = instr(lngCT,strData,chr(13) & chr(10)) + 4
      Else
          lngBeginPos = lngEndFileName
      End if
         
'Get the ending position of the file data sent.
      lngEndPos = len(strData)

'Calculate the file size.
      lngDataLenth = lngEndPos - lngBeginPos
'Get the file data
      strFileData = mid(strData,lngBeginPos,lngDataLenth)
'Create the file.
      Set fso = CreateObject("Scripting.FileSystemObject")
         
      ' Here you change the path of where to is your file going in your server
      Set f = fso.OpenTextFile(server.mappath(".") & "\" & FileName, ForWriting, True)
      f.Write strFileData
      Set f = nothing
      Set fso = nothing

      lngNumberUploaded = lngNumberUploaded + 1

  End if

'Get then next boundry postitions if any
  lngCurrentBegin = instr(1,strDataWhole,strBoundry)
lngCurrentEnd = instr(lngCurrentBegin + 1,strDataWhole,strBoundry) - 1
loop
      Response.Write "<H2>File(s) Uploaded</H2>"
      Response.Write lngNumberUploaded & " files have been uploaded.<BR>"
      Response.Write "<BR><BR><INPUT type='

-------------
Cristian Banu
http://www.soft4web.ro - Soft 4 web




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net