File Upload Size Checker

When you allow file uploading... Set a File Max Size and reject the file if it is too large.

Others will check it after it is uploaded.. then deletes it if too large.. but not this... it won't let them even upload a single bit... if it is too large! 

It will upload the file to a folder in the C directory called ?uploads? so you need to have the tag available and access to the path.

////////////////////////////////////////////////////////


<!--- upload/index.cfm --->

<CFIF isdefined ("FORM.Upload")>

    <CFIF VAL(CGI.CONTENT_LENGTH) GT 20000>

         <cflocation addtoken=
"no"
                         url=
"index.cfm?Note=File too Large! (#VAL(CGI.CONTENT_LENGTH/1000)# KB)">
         <CFABORT>

    <CFELSE>

       <CFFILE 
                ACTION=
"Upload" 
                FILEFIELD=
"UploadMe" 
                DESTINATION=
"C:\uploads\" 
                NAMECONFLICT=
"OVERWRITE">

       <cflocation addtoken=
"no"
                       url=
"index.cfm?Note=File Uploaded (#VAL(CGI.CONTENT_LENGTH/1000)# KB)">
       <CFABORT>

    </CFIF>

</CFIF>


<html>
  <head>
     <title>
Upload</title>
  </head>

<body>


<cfparam name="URL.Note" default="">
<CFOUTPUT>
   <strong><font color=
"RED">#URL.NOTE#</font></strong>
</CFOUTPUT>

<form action="index.cfm" method="post" enctype="multipart/form-data">
<input name="UPLOAD" type="hidden" value="Y">
Source File Name:<BR>
<INPUT NAME="UploadMe" TYPE="File" SIZE="50"><BR>
<input type="Submit" value="Upload Now">
</form>


</BODY>
</HTML>

////////////////////////////////////////////////////////



All ColdFusion Tutorials By Author: David McIntosh
  • File Upload Size Checker
    When you allow file uploading... Set a File Max Size and reject the file if it is too large. Others will check it after it is uploaded.. then deletes it if too large.. but not this... it won't let them even upload a single bit... if it is too large!
    Author: David McIntosh
    Views: 17,432
    Posted Date: Monday, May 5, 2003