How To The Write `<cffile action=”read”>` Function In ColdFusion?
Description:-
It reads a text file on the server. The file is read into a dynamic, local variable that you can use in the page. For example:
1. Read a text file; insert the file’s contents into a database or other.
2. Read a text file; use the find and replace function to modify the file’s contents.
<cffile
action = "read"
file = "full pathname"
variable = "variable name"
charset = "character set option"
>
cfscript the equivalent of the upper syntax
<cfscript>
cffile(
action = "read",
file = "full pathname",
variable = "variable name",
charset = "character set option"
);
</cfscript>
Attributes:-
action:- This is a required attribute, the type of file manipulation that the tag performs.
file:- This is a required attribute, The pathname of the file to which need to read.
variable:- This is a required attribute, the Name of the variable to contain the contents of the text file.
charset:- This is a non-required attribute, JVM default file character set for the default value, The character encoding in which the file contents are encoded. The following list includes commonly used values:-utf-8iso-8859-1windows-1252us-asciishift_jisiso-2022-jpeuc-jpeuc-krbig5euc-cnutf-16
Example:-
The following example creates a variable named testMessage for the contents of the file message.txt:
<cffile
action = "read"
file = "d:\files\documents\testNote.txt"
variable = "testMessage"
>
The variable Message can be used in the page. For example, you could display the contents of the message.txt file on the final web page as follows:
<cfoutput>#testMessage#</cfoutput>
Note:- This action reads the file into a variable in the local Variables scope. It is not intended for use with large files, such as logs, because this can bring down the server.
