Frequently Asked Questions

Help Center Search

How do I use cffile to upload files?

Print this Article
Comment on this Article
Last Updated: April 19, 2007 9:46 AM

Using the ColdFusion tag "cffile" allows you to create a web page that supports uploading files to your site.

We use security sandboxes for each user to ensure that users cannot upload files outside of their content directory. Also, for security purposes you should always restrict the type of files that can be uploaded to your site by using the "accept" attribute in the "cffile" tag.

For more information about controlling the type of file uploaded, please see Macromedia’s online documentation.

The following example displays an upload form that uses the "cffile" tag to perform the file upload:

<html>
<head>
<title>Upload File with ColdFusion</title>
</head>
<cfif isdefined("form.upload_now")>
<cffile action="upload" filefield="ul_path" destination="D:\Hosting\username\upload" accept="image/jpeg, image/gif" nameconflict="makeunique">
The file was successfully uploaded!
</cfif>

<form action="gd_upload.cfm" method="post" name="upload_form" enctype="multipart/form-data" id="upload_form">
<input type="file" name="ul_path" id="ul_path">
<input type="submit" name="upload_now" value="submit">
</form>
</body>
</html>

NOTE: For Linux hosting accounts, uploading files to your root directory is not supported. Also, for the "cffile" to function properly and for maximum security you should set the permissions of your upload folder to 703.

For more information on the cffile tag, please see Macromedia’s online documentation.