Coldfusion: allowing max file size when uploading
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.
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>
Other ColdFusion Articles
- Adobe Coldfusion Tip For Finding Duplicate Records In SQL Database
- Coldfusion: allowing max file size when uploading
- ColdFusion: Monitor Hard Drive Space And Email Alert
- Coldfusion SQL Tips: Creating Tables, Backup, Fields
- Coldfusion Programming: Accessing a shared network drive
- Coldfusion: Encrypting and Decrypting Data
- Adobe Coldfusion Help: Query To Spreadsheet
- ColdFusion: Upload a pipe delimited file and insert into SQL table
- Coldfusion programming: How to submit muliple records at the same time that have the same field name
- How To Upload Multiple Files With ColdFusion
More by this Author
This article will tell you how to make your baby's powder formula more consistent like the premixed ready-to-feed formula. You will save money using the powder and your baby won't know the difference!
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,...
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...