Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Limiting the size of a folder
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Limiting the size of a folder

 Post Reply Post Reply
Author
zaboss View Drop Down
Senior Member
Senior Member


Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
Post Options Post Options   Thanks (0) Thanks(0)   Quote zaboss Quote  Post ReplyReply Direct Link To This Post Topic: Limiting the size of a folder
    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
Soft 4 web
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.