How can I limit the size of a file when uploading with cffile?

You can use the cgi.content_length to find the file size. If the cgi.content_length is less than or equal to the maximum size specified the file is uploaded (saved) to the server.

<cfset fileSizeLimit = 60000 />
<cfif cgi.content_length LTE fileSizeLimit>
	<cffile action="UPLOAD"
        accept="image/gif, image/jpeg">
	Your file size of #cgi.content_length# is too big!
	The maximum size allowed is #fileSizeLimit#.

Please note with this example the file is still uploaded as a temporary file, but the file is not saved. File sizes can also be restricted in the ColdFusion Administrator by using the setting, "Maximum size of post data." However, the example above gives more granular control.

This question was written by Stan Winchester
It was last updated on January 30, 2006.


File and Directory Access


comments powered by Disqus