CFCONTENT |
Description Does either or both of the following:

- Sets the MIME content encoding header for the current page; if the encoding information includes a character encoding, sets the character encoding of generated output.
- Sends the contents of a file, or of a variable that contains binary data, as the page output.

To restrict this tag, use the Sandbox Security feature of the ColdFusion MX Administrator. For more information, see the Administrator online Help.

Category Data output tags
Syntax
    <cfcontent
       type = "file_type"
       deleteFile = "yes" or "no"
       file = "filename"
       variable = "variablename"
       reset = "yes" or "no">
See also cfcol, cfheader, cfhttp, cfoutput, cftable
History ColdFusion MX 7: Added the variable attribute.
Usage To set the character encoding (character set) of generated output, including the page HTML, use code such as the following:
    <cfcontent type="text/html; charset=ISO-8859-1">
When ColdFusion processes an HTTP request, it determines the character encoding to use for the data it returns in the HTTP response. By default, ColdFusion returns character data using the Unicode UTF-8 format, regardless of the value of an HTML meta tag in the page. You can use the cfcontent tag to override the default character encoding of the response. For example, to tell ColdFusion MX to return the page using Japanese EUC character encoding, use the type attribute, as follows:
    <cfcontent type="text/html; charset=EUC-JP">
If you call the cfcontent tag from a custom tag, and you do not want the tag to discard the current page when it is called from another application or custom tag, set reset = "no". If a file delete operation is unsuccessful, ColdFusion throws an error.

Do not use this tag after the cfflush tag on a page, it will have no effect or ColdFusion will throw an error.

The following tag can force most browsers to display a dialog box that asks users whether they want to save the contents of the file specified by the cfcontent tag using the filename specified by the filename value. If the user selects to open the file, most browsers open the file in the related application, not the browser window.

    <cfheader name="Content-Disposition" value="attachment;
    filename=filename.ext">

Some file types, such as PDF documents, do not use executable code and can display directly in most browsers. To request the browser to display the file directly, use a cfheader tag similar to the following:

    <cfheader name="Content-Disposition" value="inline; filename=name.ext">

You can use any value for the filename part of the filename attribute, but the ext part must be the standard Windows extension for the file type.

For file types that might contain executable code, such as Microsoft Excel documents, most browsers always ask before opening the document. For these file types, the inline content disposition specification requests the browser to display the file directly if the user selects to open the file.

For more information on character encodings, see the following web pages:

- www.w3.org/International/O-charset.html provides general information on character encodings and the web, and has several useful links.
- www.iana.org/assignments/character-sets is a complete list of character sets names used on the Internet, maintained by the Internet Assigned Numbers Authority.
- java.sun.com/j2se/1.3/docs/guide/intl/encoding.doc.html lists the character encodings that Java, and therefore ColdFusion, can interpret. This list uses Java internal names, not the IANA character encoding names that you use in the SetEncoding charset parameter and other ColdFusion attributes and parameters. ColdFusion MX 6.0 Updater 3 uses JDK 1.3. CFMX 6.1 uses JDK 1.4.2; for encoding support, see http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html.

For a complete list of media types used on the Internet, see www.iana.org/assignments/media-types/.

Example
    <!--- CFCONTENT Example 1
    This example shows the use of cfcontent to return the contents of the CF
    Documentation page dynamically to the browser. You might need to change the
    path and/or drive letter depending on how ColdFusion is installed on your
    system. Notice that the graphics do not display and the hyperlinks do not work,
    because the html page uses relative filename references.
    The root of the reference is the ColdFusion page, not the location of the
    html page. --->

    <cfcontent type = "text/html"
    file = "C:\CFusionMX7\wwwroot\cfdocs\dochome.htm"
    deleteFile = "no">

    <!--- CFCONTENT EXAMPLE 2
    This example shows how the Reset attribute changes text output. Notice how the
    first text section ("This example shows how the Reset attribute changes output
    for text reset = "Yes":123) does NOT print out to the screen. --->

    <p>This example shows how the Reset attribute changes output for text.</p>
    <p>reset = "Yes": 123 <BR> <cfcontent type = "text/html" reset = "Yes">456</p>
    <p>This example shows how the Reset attribute changes output for text.</p>
    <p>reset = "No": 123 <BR> <cfcontent type = "text/html" reset = "No">456</p>
    <!--- CFCONTENT EXAMPLE 3
    This example triggers a download of an Excel file. The user will be prompted
    with an option to save the file or open it in the browser. --->

    <cfheader name="Content-Disposition" value="inline; filename=acmesales03.xls">
    <cfcontent type="application/vnd.ms-excel" file="c:\temp\acmesales03.xls">

    <!--- CFCONTENT EXAMPLE 4
    This example triggers a download of a Word document then deletes the original
    from the "temp" directory. The user will be prompted
    with an option to save the file or open it in the browser. --->

    <cfheader name="Content-Disposition" value="inline; filename=temp.doc">
    <cfcontent type="application/msword" file="c:\temp\Cable.doc"
    deletefile="yes">

    <!--- CFCONTENT EXAMPLE 5
    This example causes the browser to treat the HTML table as Excel data.
    Excel interprets the table format.
    Because Excel can include executable code, the browser prompts the user whether
    to save the file or open it in a browser. --->

    <cfheader name="Content-Disposition" value="inline; filename=acmesalesQ1.xls">
    <cfcontent type="application/vnd.msexcel">

    <table border="2">
    <tr><td>Month</td><td>Quantity</td><td>$ Sales</td></tr>
    <tr><td>January</td><td>80</td><td >$245</td></tr>
    <tr><td>February</td><td>100</td><td>$699</td></tr>
    <tr><td>March</td><td>230</td><td >$2036</td></tr>
    <tr><td>Total</td><td>=Sum(B2..B4)</td><td>=Sum(C2..C4)</td></tr>
    </table>

TYPE |
| Optional
The MIME content type of the page, optionally followed by a semicolon and the character encoding. By default, ColdFusion sends pages as text/html content type in the UTF-8 character encoding. The content type determines how the browser or client interprets the page contents.

The following are some of the content type values you can use:

- text/html
- text/plain
- application/x-shockwave-flash
- application/msword
- image/jpeg

The following list includes commonly used character encoding values:

- utf-8
- iso-8859-1
- windows-1252
- us-ascii
- shift_jis
- iso-2022-jp
- euc-jp
- euc-kr
- big5
- euc-cn
- utf-16

For example:

type = "text/html"

type = "text/html; charset=ISO-8859-1"

DELETEFILE |
| Optional
Default value: "no" Applies only if you specify a file with the file attribute.

- yes: deletes the file on the server after sending its contents to the client.
- no: leaves the file on the server.

FILE |
| Optional
Name of file whose contents will be the page output. The file name must start with a drive letter and a colon, or a forward or backward slash. When using ColdFusion in a distributed configuration, the file attribute must refer to a path on the system on which the web server runs. When you use this attribute, any other output on the current CFML page is ignored; only the contents of the file are sent to the client.

VARIABLE |
| Optional
Name of a ColdFusion MX binary variable whose contents can be displayed by the browser, such as the contents of a chart generated by the cfchart tag or a PDF or Excel file retrieved by a cffile action="readBinary" tag. When you use this attribute, any other output on the current CFML page is ignored; only the contents of the file are sent to the client.

RESET |
| Optional
Default value: "yes" If you specify a file or variable attribute, this attribute has no effect; otherwise, it does the following:

- yes: discards output that precedes call to cfcontent
- no: preserves output that precedes call to cfcontent. In this case, all output is sent with the specified type.