Quackit Logo
HTML
CSS
Scripting
Database
Hosting
Design
XML
Website builder

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#">

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

Enjoy this page?

  1. Add this page to your Favorites
  2. Link to this page (copy/paste into your own website or blog):
  3. Link to Quackit using one of these banner ads.

Thanks for supporting Quackit!