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.
<cfset dateAccessed = "This page was accessed at this time: " & now()> <cffile action="write" file="C:\docs\accessLog.txt" output="#dateAccessed#">
If required, you can use any of the following attributes:
- Allows you to set permissions on Unix platforms.
- Allows you to specify whether the file should be read only, hidden, or normal.
- Lets you specify the character set to use. For example, UTF-8, ISO-8859-1, UTF-16 etc