Coldfusion: allowing max file size when uploading

Introduction:

As a web developer, you will build routines or functions to allow the user to upload an image, xls file, pdf file, etc. It is always a good rule, to limit the max file size that the user is uploading. This will eliminate other issues that may arise due to a large file being uploaded. One that comes to mind, is a timeout issue, which than leads to a frustrated user. Try to build your web applications with the user in mind. Limit any possible pitfalls that could occur on the user side.

Coldfusion Code:

Below is the sample Coldfusion code when the file is uploaded.

<cfscript>
// if the form is submitted, do the following
</cfscript>

<CFIF isdefined ("uploadfile")>

    <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="whatfile" 
                DESTINATION="C:\customer\uploads\" 
                NAMECONFLICT="OVERWRITE">

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

    </CFIF>

</CFIF>

HTML Form Code:

below is the sample HTML for the form that will actually upload the file.

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

<cfform action="index.cfm?uploadfile=yes" method="post" enctype="multipart/form-data">
What File:
<BR>
<cfINPUT NAME="WhatFile" TYPE="File" SIZE="60" required="yes" message="Please select file">
<BR>
<input type="Submit" value="Upload File">
</cfform>

More by this Author

  • Gun Laws in Georgia
    38

    Firearms can be a very dangerous tool in the hands of the wrong person. Every state has their own gun laws and regulations. For the state of Georgia, the laws are pretty straight forward and easy to abide by. Before you...

  • How to Get Rid of Mice In and Around The House?
    5

    Until this year, the only time that I've had mice or rats in the house were when my daughter had pet mice and rats, and one of those times we did have one loose in the house. (Science fair project got loose.) Anyway,...

  • How to Build Wooden Roof Trusses
    21

    You may refer to a truss as the rafter, but it's basically the skeleton of the roof, carrying the weight of the frame and supporting the walls of the building. Trusses are very important to preventing the walls from...


Click to Rate This Article
working