ColdFusion 9.0 Resources |
cfcontentDescriptionDoes either or both of the following:
To restrict this tag, use the settings in the ColdFusion Administrator > Security > Sandbox Security. For more information, see the Administrator online Help. Syntax<cfcontent deleteFile = "yes|no" file = "filename" reset = "yes|no" type = "file type" variable = "variable name"> Note: You
can specify this tag’s attributes in an 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.
HistoryColdFusion 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. Attributes
UsageTo 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:
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:\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> |