Whatever message this page gives is out now! Go check it out!

Enforcing size restrictions

Last update:
May 18, 2026
ColdFusion provides several functions for retrieving information associated with images, including the height and width of an image. For example, you can use the ImageGetWidth and ImageGetHeight functions to determine whether an image is too large to upload to a website or database.

The following example shows how to prevent users from uploading images that are greater than 300 pixels wide or 300 pixels high:
<cfimage action="read" source="#fileUpload.serverFile#" name="myImage">

<!--- Determine whether the file is greater than 300 pixels in width or height. --->

<cfif ImageGetHeight(myImage) gt 300 or ImageGetWidth(myImage) gt 300>

<!--- If the file exceeds the size limits, delete it from the server. --->

<cffile action="delete" file="#fileUpload.serverDirectory#/#fileUpload.serverFile#">

<cfoutput>

<!--- Display the following message. --->

<p>

The image you uploaded was too big. It must be less than 300 pixels wide and 300 pixels

high. Your image was #imageGetWidth(myImage)# pixels wide and

#imageGetHeight(myImage)# pixels high.

</p>

</cfif>
For information about retrieving image metadata, see the ImageGetEXIFTagImageGetIPTCTag, and ImageInfo functions in the CFML Reference.

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page