Does either or both of the following:
To restrict this tag, use the Sandbox Security feature of the ColdFusion MX Administrator. For more information, see the Administrator online Help.
<cfcontent
type = "file_type"
deleteFile = "yes" or "no"
file = "filename"
variable = "variablename"
reset = "yes" or "no">
cfcol
,
cfheader
,
cfhttp
,
cfoutput
,
cftable
ColdFusion MX 7: Added the variable
attribute.
Attribute | Req/Opt | Default | Description |
---|---|---|---|
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:
The following list includes commonly used character encoding values:
For example: type = "text/html" type = "text/html; charset=ISO-8859-1" |
deleteFile |
Optional |
no |
Applies only if you specify a file with the
|
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 |
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 |
reset |
Optional |
yes |
If you specify a
|
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:
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/.
<!--- 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>