ColdFusion Write File

Just as you can use ColdFusion to read a file from the server, you can also write a file to the server. You do this using the same tag you use to read files — the <cffile> tag.

Using the <cffile> tag, you can create a file, call it what you like, and fill it with whatever content you like. The content could be a simple hardcoded string, or it could be the contents of a variable, or both.

Example of Writing a File

This example declares a variable, assigns the current date and time to it, then writes the result to a file.

Optional Attributes

If required, you can use any of the following attributes:

mode
Allows you to set permissions on Unix platforms.
attributes
Allows you to specify whether the file should be read only, hidden, or normal.
charSet
Lets you specify the character set to use. For example, UTF-8, ISO-8859-1, UTF-16 etc