By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,092 Members | 1,546 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,092 IT Pros & Developers. It's quick & easy.

Triggering a "Exceeds Max File Size" error in freeASPUpload

P: 2
I'm using freeASPupload and got some assistance integrating to a Member script. It works successfully.

In this modified version there are two groups that use this upload script. Members of one group get automatically re-directed after uploading.

However, this member group never gets the benefit of knowing if they've uploaded an incorrect file size or incorrect file extension.

Members from the second group do see the "exceeds max file size”, and the error “invalid filetype”.

Can you take a look at the script below and suggest how I can adjust the script so that PPL members, will trigger the "Exceeds max file size error" and "invalid filetype" error, if appropriate, before they're automatically re-directed? Thank you. Any help would be appreciated.

Expand|Select|Wrap|Line Numbers
  1. <%@ Language=VBScript %>
  2. <%
  3. 'option explicit
  4. Response.Expires = -1
  5. Server.ScriptTimeout = 600
  6. Dim MMS_GROUP_NUMBER
  7.     MMS_GROUP_NUMBER = "2,3"
  8. Call OPEN_DB()
  9.     set PPLRS = MyConn.Execute( "SELECT * from mms_tbl_user_cate where fldUSER_ID = " & session( "PMMS_ID" ) & " AND fldCATE_ID = 3" )
  10.  
  11.     IF NOT PPLRS.EOF THEN
  12.     PPL_GROUP_MEMBER = "Y"
  13.  END IF
  14.  set PPLRS = nothing
  15.  MyConn.close
  16.     Set MyConn = Nothing
  17. %>
  18. <!--#include virtual="aspUpload.asp" -->
  19. <!--#include VIRTUAL="app_config.asp"-->
  20. <!--#include VIRTUAL="inc_enforce.asp"-->
  21. <!--#include file="inc_header.asp"-->
  22. <%
  23.  
  24. ' ****************************************************
  25.   Dim uploadsDirVar
  26.   uploadsDirVar = "C:\Input"
  27.   'response.write uploadsDirVar
  28. ' ****************************************************
  29. function OutputForm()
  30. %>
  31.     <form name="frmSend" method="POST" enctype="multipart/form-data" action="upload.asp" onSubmit="return onSubmitForm();">
  32.  <B></B><br><input name="attach1" type="file" size=35><br>
  33.     <!--File 2: <input name="attach2" type="file" size=35><br>-->
  34.     <!--File 3: <input name="attach3" type="file" size=35><br>-->
  35.     <!--File 4: <input name="attach4" type="file" size=35><br>-->
  36.     <br>
  37.  <!-- These input elements are obviously optional and just included here for demonstration purposes -->
  38.  <!--<B>Additional fields (demo):</B><br>-->
  39.  <!--Enter a number: <input type="text" name="enter_a_number" size="20"><br>-->
  40.     <!--Checkbox values: <input type="checkbox" value="1" name="checkbox_values">-1 <input type="checkbox" value="2" name="checkbox_values">-2<br>-->
  41.  <!-- End of additional elements -->
  42.     <input style="margin-top:4" type=submit value="Upload">
  43.     </form>
  44. <%
  45. end function
  46. function TestEnvironment()
  47.     Dim fso, fileName, testFile, streamTest
  48.     TestEnvironment = ""
  49.     Set fso = Server.CreateObject("Scripting.FileSystemObject")
  50.     if not fso.FolderExists(uploadsDirVar) then
  51.         TestEnvironment = "<B>Folder " & uploadsDirVar & " does not exist.</B><br>The value of your uploadsDirVar is incorrect. Open upload.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions."
  52.         exit function
  53.     end if
  54.     fileName = uploadsDirVar & "\test.txt"
  55.     on error resume next
  56.     Set testFile = fso.CreateTextFile(fileName, true)
  57.     If Err.Number<>0 then
  58.         TestEnvironment = "<B>Folder " & uploadsDirVar & " does not have write permissions.</B><br>The value of your uploadsDirVar is incorrect. Open upload.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions."
  59.         exit function
  60.     end if
  61.     Err.Clear
  62.     testFile.Close
  63.     fso.DeleteFile(fileName)
  64.     If Err.Number<>0 then
  65.         TestEnvironment = "<B>Folder " & uploadsDirVar & " does not have delete permissions</B>, although it does have write permissions.<br>Change the permissions for IUSR_<I>computername</I> on this folder."
  66.         exit function
  67.     end if
  68.     Err.Clear
  69.     Set streamTest = Server.CreateObject("ADODB.Stream")
  70.     If Err.Number<>0 then
  71.         TestEnvironment = "<B>The ADODB object <I>Stream</I> is not available in your server.</B><br>Check the Requirements page for information about upgrading your ADODB libraries."
  72.         exit function
  73.     end if
  74.     Set streamTest = Nothing
  75. end function
  76. function SaveFiles
  77.     Dim Upload, fileName, fileSize, ks, i, fileKey
  78.     Set Upload = New FreeASPUpload
  79.     Upload.setMaxFileSize 2, "k"
  80.     Upload.Save(uploadsDirVar)
  81.  
  82.  ' If something fails inside the script, but the exception is handled
  83.  If Err.Number<>0 then Exit function
  84.     SaveFiles = ""
  85.     ks = Upload.UploadedFiles.keys
  86.     if (UBound(ks) <> -1) then
  87.         SaveFiles = "<B>Files uploaded:</B> "
  88.         for each fileKey in Upload.UploadedFiles.keys
  89.             SaveFiles = SaveFiles & Upload.UploadedFiles(fileKey).FileName & " (" & Upload.UploadedFiles(fileKey).Length & "B) "
  90.         next
  91.     else
  92.         SaveFiles = "The file name specified in the upload form does not correspond to a valid file in the system."
  93.     end if
  94.  SaveFiles = SaveFiles & "" & Upload.Form("enter_a_number") & "<br>"
  95.  SaveFiles = SaveFiles & "" & Upload.Form("checkbox_values") & "<br>"
  96. end function
  97. SUB updateDB_Logout
  98.  Call OPEN_DB()
  99.  MyConn.Execute( "UPDATE mms_tbl_user SET fldSTATUS = '" & drpSTATUS(3) & "' WHERE ID = " & Session("PMMS_ID") )
  100.  IF Session("PMMS_IN") = "True" THEN
  101.             Call APPEND_LOG(False, Session("PMMS_ID"), "Logs out.", Trim(sysVAL(7)))
  102.         END IF
  103.   MyConn.close
  104.         Set MyConn = Nothing
  105.   Session.Abandon
  106.         Response.Redirect( "PPL_Logout.asp" )
  107.         Response.end
  108. END SUB
  109. %>
  110.  
  111. <HTML>
  112. <HEAD>
  113. <Title>TEST</Title>
  114. <style type="text/css">
  115. body {margin: 1px 100px; padding: 1px; 0px}
  116. </style>
  117. </HEAD>
  118. <BODY leftMargin=0 topMargin=0 marginheight="0" marginwidth="0"  body {border-left: 1px solid #000; }>
  119. <SCRIPT LANGUAGE="JavaScript">errorcolor = '#eeeeee';</Script>
  120. <table cellspacing=0 border=0 cellpadding=40 width=100% align=left>
  121.  <tr>
  122.   <td align=left valign=middle>
  123. <script language="JAVASCRIPT">
  124.  var errfound = false;
  125.   function ValidLength(item, len) {
  126.      return (item.length >= len);
  127.   }
  128.   function error(elem, text) {
  129.      if (errfound) return;
  130.      window.alert(text);
  131.      elem.select();
  132.      elem.focus();
  133.      elem.style.backgroundColor=errorcolor;
  134.      errfound = true;
  135.   }
  136.   function Validate() {
  137.      errfound = false;
  138.      d=document.login
  139.      if (!ValidLength(d.members_username.value,1))error(d.members_username,"Username should not be blank.");
  140.      if (!ValidLength(d.members_password.value,1))error(d.members_password,"Password should not be blank.");
  141.      return !errfound;
  142.   }
  143. </script>
  144. <TR valign=top>
  145. <div style="border:0px solid #000000; width: 705px; padding-left: 75px; text-align:top;">
  146.  
  147. <style>
  148. BODY {background-color: white;font-family:arial; font-size:12}
  149. </style>
  150. <script>
  151. function onSubmitForm() {
  152.     var formDOMObj = document.frmSend;
  153.     if (formDOMObj.attach1.value == "" && formDOMObj.attach2.value == "" && formDOMObj.attach3.value == "" && formDOMObj.attach4.value == "" )
  154.         alert("Please press the browse button and pick a file.")
  155.     else
  156.         return true;
  157.     return false;
  158. }
  159. </script>
  160. </HEAD>
  161. <BODY>
  162. <br><br>
  163. <div style="border-bottom: #A91905 2px solid;font-size:16">1. Select(Click) the Browse Button<br>
  164. 2. Choose Your File For Uploading<br>
  165. 3. Select(Click) the Upload Button<br><br></div>
  166. <%
  167. Dim diagnostics
  168. if Request.ServerVariables("REQUEST_METHOD") <> "POST" then
  169.     diagnostics = TestEnvironment()
  170.     if diagnostics<>"" then
  171.         response.write "<div style=""margin-left:20; margin-top:30; margin-right:30; margin-bottom:30;"">"
  172.         response.write diagnostics
  173.         response.write "<p>After you correct this problem, reload the page."
  174.         response.write "</div>"
  175.     else
  176.         response.write "<div style=""margin-left:5"">"
  177.         OutputForm()
  178.         response.write "</div>"
  179.     end if
  180. else
  181.     response.write "<div style=""margin-left:5"">"
  182.     OutputForm()
  183.     response.write SaveFiles()
  184.     response.write "<br><br></div>"
  185.     IF PPL_GROUP_MEMBER = "Y" THEN
  186.      updateDB_Logout
  187.  end if
  188. end if
  189. %><img src="img/linkimg9.jpg" style="vertical-align: middle;" width="32" height="27" alt="" border="0" />
  190. <span style="color: #ffffff"><%=Trim(Session("PMMS_EMAIL"))%>
  191. </span>
  192. <br><br>
  193. </p></div></tr></td></tr>
  194. </table></TD></TR><!--#include file="inc_footer.asp"--></TABLE>
  195.   </TD>
  196.  </TR>
  197. </TABLE>
  198. <TABLE cellSpacing=0 valign=bottom cellPadding=0 width=100% border=0>
  199.  <TR valign=top height=4>
  200.  </TR>
  201.  <TR valign=middle height=25>
  202.   <TD class=headera2>&nbsp;<FONT class=linksmall><font face="Arial" color="#ffffff" size="2">Copyright © 2007 <a href="" target="_blank"></a>. All Rights Reserved.</FONT></TD>
  203.   <TD align=right class=headera2><font class=linksmall><font face="Arial" color="#ffffff" size="2">Email : <A href=""></A> &nbsp;&nbsp;&nbsp; </font></TD>
  204.  </TR>
  205. </TABLE>
  206. </Body>
  207. </BODY>
  208. </HTML>
Apr 18 '08 #1
Share this Question
Share on Google+
1 Reply


jhardman
Expert 2.5K+
P: 3,405
The first thing I would do is comment out the response.redirect line, then put in a whole bunch of response.write "<!-- line 25 executed -->" style lines so you can see what lines are executing and which lines aren't. Does this make sense?

Jared
Apr 21 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.