472,353 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

Triggering a "Exceeds Max File Size" error in freeASPUpload

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
1 5224
jhardman
3,406 Expert 2GB
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

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

Similar topics

3
by: Bob Lidgard | last post by:
Hi, I need some help. Hopefully this is trivial! I have created a special file type for my application. I can easily associate the app with the...
7
by: Joe | last post by:
I have an upload file operation in the web application. UploadForm.asp is the form, and UploadAction.asp is the form processing. ...
1
by: Mark Sandfox | last post by:
Is there a way to restrict the user to only selecting and sending either a ..gif or .jpg. Everything I have read says this option can not be done...
2
by: IkBenHet | last post by:
Hello, I am uploading a file using this form in ASP.NET. I have also added a simpel textfield: <form runat="server"...
0
by: yma | last post by:
Hi, I have a web.config file that contains <httpHandlers> section that causes "cannot load file..." error. If I delete this section, it is OK. ...
0
by: smanisankar | last post by:
hi, the following is the full page code for uploading a file to server. since i got no idea to overwrite the file, i want delete the file if the...
6
Markus
by: Markus | last post by:
I'm adding to my script a section that allows a thumbnail to be created and saved. I get this error: Warning: imagejpeg() : Unable to open...
1
by: .Net Sports | last post by:
I'm using Persits.upload module in ASP, and when i use the following form pointed to the object I've always used, i get a "The system cannot find...
0
by: =?Utf-8?B?eHl6X2phdA==?= | last post by:
I have a winodws service which sends email using Domino. The service is installed using System Account but it is not able to send emails and gives...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.