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 settings in the ColdFusion Administrator > Security > Sandbox Security. For more information, see the Administrator online Help.
Data output tags
<cfcontent
deleteFile = "yes|no"
file = "filename"
reset = "yes|no"
type = "file type"
variable = "variable name">
attributeCollection attribute
whose value is a structure. Specify the structure name in the attributeCollection attribute
and use the tag’s attribute names as structure keys.ColdFusion
8: Changed the behavior of the tag if the type attribute
is not specified and the file attribute is specified.
Previously, ColdFusion assumed a default file type of text/html.
Now, ColdFusion attempts to get the content type from the file.
ColdFusion
MX 7: Added the variable attribute.
Attribute |
Req/Opt |
Default |
Description |
|---|---|---|---|
|
Optional |
|
Applies only if you specify a file with
the
|
|
Optional |
Name of an on-disk or in-memory file whose
contents provide the page output. The filename must start with a
drive letter and a colon, or a forward or backward slash. When using
ColdFusion in a distributed configuration, the |
|
|
Optional |
|
If you specify a
|
|
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. However, if the The content type determines how the browser or client interprets the page contents. The following are some of the content type values that you can use:
The following list includes commonly used character encoding values:
For example:
|
|
|
Optional |
Name of a ColdFusion binary variable whose
contents can be displayed by the browser, such as the contents of
a chart generated by the |
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
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 has no effect or ColdFusion throws 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:
The page atwww.w3.org/International/O-charset.html provides general information on character encodings and the web, and has several useful links.
The page at 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.
ColdFusion uses the Java JCE for encoding support. The page at http://java.sun.com/javase/6/docs/technotes/guides/intl/encoding.doc.html lists the character encodings that JCE 6, 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.
For a complete list of media types used on the Internet, see www.iana.org/assignments/media-types/.
<!--- 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:\ColdFusion9\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 is 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 is 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>