cffile action = "read"

Description

Reads a text file. The file is read into a dynamic parameter that you can use anywhere in the page, like any other dynamic parameter. For example, you could read a text file and then insert its contents into a database, or you could read a text file and then use the find and replace functions to modify its contents.


Note

Using cffile action = "READ" reads the entire text file into memory. Therefore, it is not intended for use with extremely large files, such as log files, because they can bring down the server.


Category

File management tags

Syntax

<cffile action = "read"
  file = "full_path_name"
  variable = "var_name"> 

See also

cfdirectory

Attributes

Attribute
Description
file
Required. The full pathname of the text file to be read.
variable
Required. The name of the variable that will contain the contents of the text file after it has been read.

Example

The following example creates a variable named "Message " to contain the contents of the file message.txt.

<cffile action = "read" 
  file = "c:\web\message.txt" 
  variable = "Message">

The variable "Message" could then be used in the page. For example, you could display the contents of the message.txt file in the final Web page:

<cfoutput>#Message#</cfoutput>

ColdFusion supports a number of powerful functions for manipulating the contents of text files. You can also use the variable created by a cffile action = "read" operation in ArrayToList and ListToArray functions.

For more information about working with strings and arrays, see "String functions" and "Array functions".