Whatever message this page gives is out now! Go check it out!
<cfcontent
deleteFile = "yes|no"
file = "filename"
reset = "yes|no"
type = "file type"
variable = "variable name">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. |
| Attribute | Req/Opt | Default | Description | ||
deleteFile | Optional | no | Applies only if you specify a file with the file attribute.
| ||
file | 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 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. | |||
reset | Optional | yes | If you specify a file or variable attribute, this attribute has no effect; otherwise, it does the following:
| ||
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. However, if the file attribute is specified, ColdFusion attempts to get the content type from the file. 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:
| {{type = "text/html"}} {{type = "text/html; charset}}{{=}}{{ISO-8859-1}}{{"}} | ||
variable | 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 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. |
<cfcontent type="text/html; charset=ISO-8859-1"> |
<cfcontent type="text/html; charset=EUC-JP"> |
<cfheader name="Content-Disposition" value="attachment; filename=filename.ext"> |
<cfheader name="Content-Disposition" value="inline; filename=name.ext"> |
When using cfabort, cflocation, or cfcontent tags, the OnAbort method is invoked instead on OnRequestEnd. |
<!--- 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><cfset documentLibrary = {
"EMP001" = {name = "Employment_Contract_2024.pdf", type = "application/pdf", size = "245 KB"},
"FIN002" = {name = "Q4_Financial_Report.pdf", type = "application/pdf", size = "1.2 MB"},
"POL003" = {name = "Company_Policy_Handbook.pdf", type = "application/pdf", size = "890 KB"},
"INV004" = {name = "Annual_Invoice_Summary.xlsx", type = "application/vnd.ms-excel", size = "156 KB"}
}>
<!--- Simulated user session --->
<cfset session.userId = "USER" & randRange(1000, 9999)>
<cfset session.userName = "John Doe">
<cfset session.userRole = "Employee">
<cfset session.isAuthenticated = true>
<!--- Download audit log --->
<cfset downloadLog = []>
<!--- Handle download request --->
<cfif structKeyExists(url, "docId") AND structKeyExists(url, "action") AND url.action EQ "download">
<cftry>
<!--- Security: Verify authentication --->
<cfif NOT session.isAuthenticated>
<cfheader statuscode="401">
<cfoutput>
<h1>Access Denied</h1>
<p>You must be logged in to download documents.</p>
</cfoutput>
<cfabort>
</cfif>
<!--- Validate document ID --->
<cfif NOT structKeyExists(documentLibrary, url.docId)>
<cfheader statuscode="404">
<cfoutput>
<h1>Document Not Found</h1>
<p>The requested document does not exist.</p>
</cfoutput>
<cfabort>
</cfif>
<!--- Get document info --->
<cfset doc = documentLibrary[url.docId]>
<!--- Log download attempt --->
<cfset auditEntry = {
timestamp = now(),
userId = session.userId,
userName = session.userName,
documentId = url.docId,
documentName = doc.name,
ipAddress = "192.168.1.100",
status = "SUCCESS"
}>
<cfset arrayAppend(downloadLog, auditEntry)>
<!--- For CFFiddle demo: Simulate file download with message --->
<!--- In production, this would serve the actual file:
<cfheader name="Content-Disposition" value="attachment; filename=#doc.name#">
<cfcontent type="#doc.type#" file="c:\secure_docs\#doc.name#">
--->
<!--- CFFiddle-compatible demonstration --->
<cfheader name="Content-Disposition" value="attachment; filename=#doc.name#">
<cfcontent type="text/plain" reset="yes">
<cfoutput>
Document Download Simulated
===========================
Document: #doc.name#
Type: #doc.type#
Size: #doc.size#
Downloaded by: #session.userName# (ID: #session.userId#)
Download Time: #dateTimeFormat(now(), "yyyy-mm-dd HH:nn:ss")#
In production, this would deliver the actual file content.
The file would be served from a secure location outside the web root.
Audit Trail:
- User authenticated: YES
- Permission verified: YES
- Download logged: YES
- IP Address: #auditEntry.ipAddress#
</cfoutput>
<cfabort>
<cfcatch type="any">
<!--- Log error --->
<cfset errorEntry = {
timestamp = now(),
userId = session.userId,
documentId = url.docId,
error = cfcatch.message,
status = "FAILED"
}>
<cfset arrayAppend(downloadLog, errorEntry)>
<cfheader statuscode="500">
<cfoutput>
<h1>Download Error</h1>
<p>An error occurred while processing your download request.</p>
<p>Error: #cfcatch.message#</p>
</cfoutput>
<cfabort>
</cfcatch>
</cftry>
</cfif>
<!DOCTYPE html>
<html>
<head>
<title>Secure Document Library</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh; padding: 20px; }
.container { max-width: 900px; margin: 0 auto; }
.header { background: white; padding: 30px; border-radius: 15px 15px 0 0;
box-shadow: 0 -5px 20px rgba(0,0,0,0.1); }
.header h1 { color: #2c3e50; margin-bottom: 10px; }
.user-info { display: flex; align-items: center; gap: 15px; padding: 15px;
background: #f8f9fa; border-radius: 8px; margin-top: 15px; }
.user-avatar { width: 50px; height: 50px; border-radius: 50%;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
display: flex; align-items: center; justify-content: center;
color: white; font-size: 24px; font-weight: bold; }
.document-list { background: white; padding: 30px; border-radius: 0 0 15px 15px;
box-shadow: 0 10px 30px rgba(0,0,0,0.2); }
.doc-item { display: flex; align-items: center; justify-content: space-between;
padding: 20px; background: #f8f9fa; border-radius: 10px;
margin-bottom: 15px; border-left: 4px solid #667eea;
transition: all 0.3s; }
.doc-item:hover { transform: translateX(5px); box-shadow: 0 5px 15px rgba(102,126,234,0.3); }
.doc-icon { font-size: 36px; margin-right: 15px; }
.doc-info { flex: 1; }
.doc-name { font-weight: bold; color: #2c3e50; margin-bottom: 5px; }
.doc-meta { font-size: 13px; color: #7f8c8d; }
.download-btn { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white; padding: 12px 24px; border: none; border-radius: 8px;
cursor: pointer; font-weight: bold; text-decoration: none;
display: inline-block; transition: all 0.3s; }
.download-btn:hover { transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(102,126,234,0.4); }
.security-notice { background: #fff3cd; padding: 15px; border-radius: 8px;
border-left: 4px solid #ffc107; margin-bottom: 20px; }
.audit-log { margin-top: 30px; background: #f8f9fa; padding: 20px;
border-radius: 10px; }
.audit-log h3 { color: #2c3e50; margin-bottom: 15px; }
.audit-entry { padding: 10px; background: white; border-radius: 5px;
margin-bottom: 10px; font-size: 14px; }
.badge { display: inline-block; padding: 4px 10px; border-radius: 12px;
font-size: 11px; font-weight: bold; margin-left: 10px; }
.badge-success { background: #28a745; color: white; }
.badge-role { background: #667eea; color: white; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🔒 Secure Document Library</h1>
<div class="user-info">
<div class="user-avatar">
<cfoutput>#left(session.userName, 1)#</cfoutput>
</div>
<div>
<cfoutput>
<strong>#session.userName#</strong>
<span class="badge badge-role">#session.userRole#</span><br>
<small style="color: ##7f8c8d;">User ID: #session.userId#</small>
</cfoutput>
</div>
<cfif session.isAuthenticated>
<span class="badge badge-success" style="margin-left: auto;">✓ AUTHENTICATED</span>
</cfif>
</div>
</div>
<div class="document-list">
<div class="security-notice">
<strong>🛡️ Security Notice:</strong> All document downloads are logged and monitored.
Files are served from secure storage outside the web root. Unauthorized access attempts
will be reported.
</div>
<h2 style="color: #2c3e50; margin-bottom: 20px;">Available Documents</h2>
<cfloop collection="#documentLibrary#" item="docId">
<cfset doc = documentLibrary[docId]>
<div class="doc-item">
<div class="doc-icon">
<cfif findNoCase(".pdf", doc.name)>
📄
<cfelseif findNoCase(".xlsx", doc.name) OR findNoCase(".xls", doc.name)>
📊
<cfelse>
📎
</cfif>
</div>
<div class="doc-info">
<div class="doc-name">
<cfoutput>#doc.name#</cfoutput>
</div>
<div class="doc-meta">
<cfoutput>
Document ID: #docId# | Size: #doc.size# | Type: #doc.type#
</cfoutput>
</div>
</div>
<cfoutput>
<a href="?docId=#docId#&action=download" class="download-btn">
⬇ Download
</a>
</cfoutput>
</div>
</cfloop>
<cfif arrayLen(downloadLog) GT 0>
<div class="audit-log">
<h3>📋 Download Audit Log</h3>
<cfloop array="#downloadLog#" index="entry">
<div class="audit-entry">
<cfoutput>
<strong>#dateTimeFormat(entry.timestamp, "yyyy-mm-dd HH:nn:ss")#</strong> -
User: #entry.userName# (#entry.userId#) -
Document: #entry.documentName# (#entry.documentId#) -
<span class="badge badge-success">#entry.status#</span>
<cfif structKeyExists(entry, "ipAddress")>
<br><small>IP: #entry.ipAddress#</small>
</cfif>
<cfif structKeyExists(entry, "error")>
<br><small style="color: ##e74c3c;">Error: #entry.error#</small>
</cfif>
</cfoutput>
</div>
</cfloop>
</div>
</cfif>
</div>
</div>
</body>
</html><cfset reportData = [
{month = "January", region = "North", units = 1250, revenue = 62500, target = 60000},
{month = "January", region = "South", units = 980, revenue = 49000, target = 45000},
{month = "January", region = "East", units = 1420, revenue = 71000, target = 70000},
{month = "January", region = "West", units = 1100, revenue = 55000, target = 50000},
{month = "February", region = "North", units = 1380, revenue = 69000, target = 60000},
{month = "February", region = "South", units = 1050, revenue = 52500, target = 45000},
{month = "February", region = "East", units = 1560, revenue = 78000, target = 70000},
{month = "February", region = "West", units = 1220, revenue = 61000, target = 50000}
]>
<cfset currentQuarter = "Q1">
<cfset currentYear = year(now())>
<cfset reportDate = dateFormat(now(), "yyyy-mm-dd")>
<!--- Handle export request --->
<cfif structKeyExists(url, "action") AND url.action EQ "export">
<!--- Set Excel-friendly filename --->
<cfset fileName = "Sales_Report_#currentQuarter#_#currentYear#_#reportDate#.xls">
<!--- Configure headers for Excel download --->
<cfheader name="Content-Disposition" value="attachment; filename=#fileName#">
<cfcontent type="application/vnd.ms-excel" reset="yes">
<!--- Generate Excel-compatible HTML table --->
<cfoutput>
<html xmlns:x="urn:schemas-microsoft-com:office:excel">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
table { border-collapse: collapse; font-family: Arial, sans-serif; }
th { background-color: ##4472C4; color: white; font-weight: bold;
padding: 10px; border: 1px solid ##ddd; }
td { padding: 8px; border: 1px solid ##ddd; }
.number { text-align: right; }
.currency { text-align: right; }
.total-row { background-color: ##E7E6E6; font-weight: bold; }
.header-row { background-color: ##F2F2F2; font-weight: bold; }
</style>
</head>
<body>
<h1>Sales Performance Report</h1>
<p><strong>Quarter:</strong> #currentQuarter# #currentYear#</p>
<p><strong>Report Generated:</strong> #dateTimeFormat(now(), "mmmm d, yyyy 'at' h:nn tt")#</p>
<p><strong>Export Date:</strong> #reportDate#</p>
<br>
<table border="1">
<thead>
<tr>
<th>Month</th>
<th>Region</th>
<th>Units Sold</th>
<th>Revenue ($)</th>
<th>Target ($)</th>
<th>vs Target (%)</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<cfset rowNum = 2> <!--- Excel row numbering starts at row 2 after header --->
<cfloop array="#reportData#" index="row">
<cfset rowNum++>
<tr>
<td>#row.month#</td>
<td>#row.region#</td>
<td class="number">#numberFormat(row.units, "999,999")#</td>
<td class="currency">#dollarFormat(row.revenue)#</td>
<td class="currency">#dollarFormat(row.target)#</td>
<!--- Excel Formula: Calculate percentage vs target --->
<td class="number">=ROUND((D#rowNum#/E#rowNum#)*100,1)</td>
<!--- Excel Formula: IF statement for status --->
<td>=IF(D#rowNum#>=E#rowNum#,"✓ Met","✗ Missed")</td>
</tr>
</cfloop>
<!--- Summary Totals Row --->
<tr class="total-row">
<td colspan="2"><strong>TOTAL</strong></td>
<td class="number">=SUM(C3:C#rowNum#)</td>
<td class="currency">=SUM(D3:D#rowNum#)</td>
<td class="currency">=SUM(E3:E#rowNum#)</td>
<td class="number">=ROUND((D#rowNum+1#/E#rowNum+1#)*100,1)</td>
<td>=IF(D#rowNum+1#>=E#rowNum+1#,"✓ ACHIEVED","✗ BELOW TARGET")</td>
</tr>
</tbody>
</table>
<br><br>
<h3>Regional Summary</h3>
<table border="1">
<thead>
<tr class="header-row">
<th>Region</th>
<th>Total Revenue</th>
<th>Avg Monthly Revenue</th>
<th>Performance</th>
</tr>
</thead>
<tbody>
<cfset regions = ["North", "South", "East", "West"]>
<cfloop array="#regions#" index="region">
<tr>
<td>#region#</td>
<!--- Use SUMIF to calculate regional totals --->
<td class="currency">=SUMIF(B3:B#rowNum#,"#region#",D3:D#rowNum#)</td>
<!--- Average formula --->
<td class="currency">=SUMIF(B3:B#rowNum#,"#region#",D3:D#rowNum#)/COUNTIF(B3:B#rowNum#,"#region#")</td>
<!--- Conditional formatting indicator --->
<td>=IF(SUMIF(B3:B#rowNum#,"#region#",D3:D#rowNum#)>120000,"⭐ Excellent",IF(SUMIF(B3:B#rowNum#,"#region#",D3:D#rowNum#)>100000,"👍 Good","📈 Needs Improvement"))</td>
</tr>
</cfloop>
</tbody>
</table>
<br><br>
<p><em>Note: This report contains Excel formulas that will calculate automatically when opened in Microsoft Excel.</em></p>
<p><em>Generated by Sales Analytics System | Confidential - Internal Use Only</em></p>
</body>
</html>
</cfoutput>
<cfabort>
</cfif>
<!DOCTYPE html>
<html>
<head>
<title>Sales Report Export</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Arial', sans-serif; background: #f5f5f5; padding: 20px; }
.container { max-width: 1200px; margin: 0 auto; background: white;
border-radius: 10px; box-shadow: 0 0 20px rgba(0,0,0,0.1); }
.header { background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
color: white; padding: 30px; border-radius: 10px 10px 0 0; }
.header h1 { font-size: 28px; margin-bottom: 10px; }
.content { padding: 30px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr);
gap: 15px; margin-bottom: 30px; }
.stat-card { background: #f8f9fa; padding: 20px; border-radius: 8px;
text-align: center; border-left: 4px solid #1e3c72; }
.stat-value { font-size: 32px; font-weight: bold; color: #1e3c72; margin: 10px 0; }
.stat-label { color: #6c757d; font-size: 14px; }
table { width: 100%; border-collapse: collapse; margin: 20px 0; }
th { background: #1e3c72; color: white; padding: 12px; text-align: left; }
td { padding: 10px; border-bottom: 1px solid #dee2e6; }
tr:hover { background: #f8f9fa; }
.number { text-align: right; }
.currency { text-align: right; font-weight: 500; }
.status-met { color: #28a745; font-weight: bold; }
.status-missed { color: #dc3545; font-weight: bold; }
.export-btn { background: #28a745; color: white; padding: 15px 30px;
border: none; border-radius: 8px; font-size: 16px;
cursor: pointer; text-decoration: none; display: inline-block;
font-weight: bold; transition: all 0.3s; }
.export-btn:hover { background: #218838; transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(40,167,69,0.3); }
.info-box { background: #e7f3ff; padding: 20px; border-radius: 8px;
border-left: 4px solid #0066cc; margin: 20px 0; }
.feature-list { display: grid; grid-template-columns: repeat(2, 1fr);
gap: 10px; margin-top: 15px; }
.feature-item { padding: 10px; background: white; border-radius: 5px;
border-left: 3px solid #28a745; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<cfoutput>
<h1>📊 Sales Performance Dashboard</h1>
<p>Quarter: #currentQuarter# #currentYear# | Report Date: #dateFormat(now(), "mmmm d, yyyy")#</p>
</cfoutput>
</div>
<div class="content">
<cfset totalUnits = 0>
<cfset totalRevenue = 0>
<cfset totalTarget = 0>
<cfloop array="#reportData#" index="row">
<cfset totalUnits += row.units>
<cfset totalRevenue += row.revenue>
<cfset totalTarget += row.target>
</cfloop>
<div class="stats-grid">
<div class="stat-card">
<div class="stat-label">Total Units Sold</div>
<div class="stat-value">
<cfoutput>#numberFormat(totalUnits, "999,999")#</cfoutput>
</div>
</div>
<div class="stat-card">
<div class="stat-label">Total Revenue</div>
<div class="stat-value">
<cfoutput>#dollarFormat(totalRevenue)#</cfoutput>
</div>
</div>
<div class="stat-card">
<div class="stat-label">Total Target</div>
<div class="stat-value">
<cfoutput>#dollarFormat(totalTarget)#</cfoutput>
</div>
</div>
<div class="stat-card">
<div class="stat-label">Achievement</div>
<div class="stat-value" style="color: <cfoutput>#totalRevenue GTE totalTarget ? '##28a745' : '##dc3545'#</cfoutput>">
<cfoutput>#numberFormat((totalRevenue/totalTarget)*100, "999.9")#%</cfoutput>
</div>
</div>
</div>
<div style="text-align: center; margin: 30px 0;">
<a href="?action=export" class="export-btn">
📥 Export to Excel
</a>
</div>
<div class="info-box">
<h3 style="color: #0066cc; margin-bottom: 15px;">✨ Excel Export Features</h3>
<div class="feature-list">
<div class="feature-item">✓ Automatic Excel formulas for calculations</div>
<div class="feature-item">✓ Formatted tables with headers and styling</div>
<div class="feature-item">✓ SUM, SUMIF, and IF functions included</div>
<div class="feature-item">✓ Regional summary with conditional logic</div>
<div class="feature-item">✓ Percentage calculations vs targets</div>
<div class="feature-item">✓ Date-stamped filename for easy filing</div>
</div>
</div>
<h2 style="color: #1e3c72; margin: 30px 0 20px 0;">Sales Data Preview</h2>
<table>
<thead>
<tr>
<th>Month</th>
<th>Region</th>
<th class="number">Units</th>
<th class="currency">Revenue</th>
<th class="currency">Target</th>
<th class="number">vs Target</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<cfloop array="#reportData#" index="row">
<cfset vsTarget = (row.revenue / row.target) * 100>
<tr>
<cfoutput>
<td>#row.month#</td>
<td>#row.region#</td>
<td class="number">#numberFormat(row.units, "999,999")#</td>
<td class="currency">#dollarFormat(row.revenue)#</td>
<td class="currency">#dollarFormat(row.target)#</td>
<td class="number">#numberFormat(vsTarget, "999.9")#%</td>
<td class="#row.revenue GTE row.target ? 'status-met' : 'status-missed'#">
#row.revenue GTE row.target ? '✓ Met' : '✗ Missed'#
</td>
</cfoutput>
</tr>
</cfloop>
</tbody>
</table>
</div>
</div>
</body>
</html><cfset documentVault = {
"POLICY001" = {
title = "Employee Handbook 2024",
type = "application/pdf",
category = "Policy",
icon = "📘",
size = "2.4 MB",
lastUpdated = "2024-01-15"
},
"TRAIN002" = {
title = "Safety Training Manual",
type = "application/pdf",
category = "Training",
icon = "🛡️",
size = "1.8 MB",
lastUpdated = "2024-02-20"
},
"CONTRACT003" = {
title = "Service Level Agreement",
type = "application/pdf",
category = "Legal",
icon = "⚖️",
size = "456 KB",
lastUpdated = "2024-03-10"
},
"CERT004" = {
title = "Compliance Certificate",
type = "application/pdf",
category = "Certificate",
icon = "🏆",
size = "234 KB",
lastUpdated = "2024-01-30"
}
}>
<cfset viewMode = structKeyExists(url, "mode") ? url.mode : "inline">
<cfset accessLog = []>
<!--- Handle document view/download request --->
<cfif structKeyExists(url, "docId") AND structKeyExists(url, "action")>
<cftry>
<!--- Validate document exists --->
<cfif NOT structKeyExists(documentVault, url.docId)>
<cfheader statuscode="404">
<cfoutput>
<h1>404 - Document Not Found</h1>
<p>The requested document does not exist in the vault.</p>
</cfoutput>
<cfabort>
</cfif>
<cfset doc = documentVault[url.docId]>
<!--- Determine content disposition based on action --->
<cfif url.action EQ "view">
<cfset disposition = "inline">
<cfset actionText = "Viewing">
<cfelse>
<cfset disposition = "attachment">
<cfset actionText = "Downloaded">
</cfif>
<!--- Log access --->
<cfset arrayAppend(accessLog, {
timestamp = now(),
docId = url.docId,
docTitle = doc.title,
action = actionText,
disposition = disposition
})>
<!--- For CFFiddle: Simulate document delivery --->
<cfheader name="Content-Disposition" value="#disposition#; filename=#replace(doc.title, ' ', '_', 'ALL')#.pdf">
<cfcontent type="text/plain" reset="yes">
<cfoutput>
#disposition EQ "inline" ? "VIEWING IN BROWSER" : "DOWNLOADING FILE"#
========================================
Document: #doc.title#
Type: #doc.type#
Category: #doc.category#
Size: #doc.size#
Last Updated: #dateFormat(doc.lastUpdated, "mmmm d, yyyy")#
Content-Disposition: #disposition#
#disposition EQ "inline" ? "This document is displayed directly in your browser.
You can read it without downloading. Use browser's built-in
PDF viewer controls. Click 'Download' if you want to save it." : "This document is being downloaded to your computer.
Check your Downloads folder. The file will be saved locally
for offline access and archival."#
Access Details:
- Document ID: #url.docId#
- Access Time: #dateTimeFormat(now(), "yyyy-mm-dd HH:nn:ss")#
- Action: #actionText#
---
PRODUCTION IMPLEMENTATION:
In a production environment, this would use:
<cfheader name="Content-Disposition" value="#disposition#; filename=#doc.title#.pdf">
<cfcontent type="#doc.type#" file="c:\document_vault\#url.docId#.pdf">
The inline mode displays PDFs directly in browser.
The attachment mode triggers download dialog.
</cfoutput>
<cfabort>
<cfcatch type="any">
<cfheader statuscode="500">
<cfoutput>
<h1>Error Loading Document</h1>
<p>An error occurred: #cfcatch.message#</p>
</cfoutput>
<cfabort>
</cfcatch>
</cftry>
</cfif>
<!DOCTYPE html>
<html>
<head>
<title>Document Viewer System</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Arial', sans-serif; background: #ecf0f1; padding: 20px; }
.container { max-width: 1200px; margin: 0 auto; }
.page-header { background: linear-gradient(135deg, #2c3e50 0%, #3498db 100%);
color: white; padding: 40px; border-radius: 15px;
box-shadow: 0 10px 30px rgba(0,0,0,0.2); margin-bottom: 30px; }
.page-header h1 { font-size: 36px; margin-bottom: 10px; }
.doc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 20px; margin-bottom: 30px; }
.doc-card { background: white; border-radius: 12px; padding: 25px;
box-shadow: 0 5px 20px rgba(0,0,0,0.1); transition: all 0.3s; }
.doc-card:hover { transform: translateY(-5px);
box-shadow: 0 10px 30px rgba(0,0,0,0.15); }
.doc-header { display: flex; align-items: center; margin-bottom: 15px; }
.doc-icon { font-size: 48px; margin-right: 15px; }
.doc-title { font-size: 18px; font-weight: bold; color: #2c3e50; }
.doc-meta { display: grid; gap: 8px; margin: 15px 0; font-size: 14px; color: #7f8c8d; }
.doc-meta-item { display: flex; justify-content: space-between;
padding: 8px 0; border-bottom: 1px solid #ecf0f1; }
.action-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 15px; }
.btn { padding: 12px; border: none; border-radius: 8px; cursor: pointer;
font-weight: bold; text-decoration: none; display: inline-block;
text-align: center; transition: all 0.3s; }
.btn-view { background: #3498db; color: white; }
.btn-view:hover { background: #2980b9; }
.btn-download { background: #27ae60; color: white; }
.btn-download:hover { background: #229954; }
.info-panel { background: white; padding: 30px; border-radius: 12px;
box-shadow: 0 5px 20px rgba(0,0,0,0.1); margin-bottom: 20px; }
.info-panel h3 { color: #2c3e50; margin-bottom: 20px; }
.comparison { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.comparison-item { padding: 20px; background: #f8f9fa; border-radius: 8px; }
.comparison-item h4 { color: #3498db; margin-bottom: 15px; }
.comparison-item ul { margin-left: 20px; color: #2c3e50; line-height: 1.8; }
.category-badge { display: inline-block; padding: 5px 12px; border-radius: 15px;
font-size: 11px; font-weight: bold; margin-top: 10px; }
.badge-policy { background: #e74c3c; color: white; }
.badge-training { background: #f39c12; color: white; }
.badge-legal { background: #9b59b6; color: white; }
.badge-certificate { background: #16a085; color: white; }
</style>
</head>
<body>
<div class="container">
<div class="page-header">
<h1>📄 Document Viewer & Download Center</h1>
<p>View documents inline or download for offline access</p>
</div>
<div class="info-panel">
<h3>🎯 Inline View vs Download</h3>
<div class="comparison">
<div class="comparison-item">
<h4>👁️ Inline View (Browser Display)</h4>
<ul>
<li>Opens directly in browser window</li>
<li>No download clutter</li>
<li>Quick preview and reading</li>
<li>Browser back button works</li>
<li>Perfect for mobile users</li>
<li>Saves device storage</li>
</ul>
</div>
<div class="comparison-item">
<h4>⬇️ Download (Save Locally)</h4>
<ul>
<li>Saves to Downloads folder</li>
<li>Available offline</li>
<li>Can be archived/shared</li>
<li>Opens in default PDF app</li>
<li>Permanent local copy</li>
<li>Editable annotations</li>
</ul>
</div>
</div>
</div>
<h2 style="color: #2c3e50; margin-bottom: 20px;">📚 Document Library</h2>
<div class="doc-grid">
<cfloop collection="#documentVault#" item="docId">
<cfset doc = documentVault[docId]>
<div class="doc-card">
<div class="doc-header">
<div class="doc-icon">
<cfoutput>#doc.icon#</cfoutput>
</div>
<div>
<div class="doc-title">
<cfoutput>#doc.title#</cfoutput>
</div>
<cfoutput>
<cfswitch expression="#doc.category#">
<cfcase value="Policy">
<span class="category-badge badge-policy">#doc.category#</span>
</cfcase>
<cfcase value="Training">
<span class="category-badge badge-training">#doc.category#</span>
</cfcase>
<cfcase value="Legal">
<span class="category-badge badge-legal">#doc.category#</span>
</cfcase>
<cfcase value="Certificate">
<span class="category-badge badge-certificate">#doc.category#</span>
</cfcase>
</cfswitch>
</cfoutput>
</div>
</div>
<div class="doc-meta">
<div class="doc-meta-item">
<span><strong>Document ID:</strong></span>
<cfoutput><span>#docId#</span></cfoutput>
</div>
<div class="doc-meta-item">
<span><strong>File Size:</strong></span>
<cfoutput><span>#doc.size#</span></cfoutput>
</div>
<div class="doc-meta-item">
<span><strong>Last Updated:</strong></span>
<cfoutput><span>#dateFormat(doc.lastUpdated, "mm/dd/yyyy")#</span></cfoutput>
</div>
<div class="doc-meta-item">
<span><strong>Type:</strong></span>
<span>PDF Document</span>
</div>
</div>
<div class="action-buttons">
<cfoutput>
<a href="?docId=#docId#&action=view" class="btn btn-view">
👁️ View Inline
</a>
<a href="?docId=#docId#&action=download" class="btn btn-download">
⬇️ Download
</a>
</cfoutput>
</div>
</div>
</cfloop>
</div>
<cfif arrayLen(accessLog) GT 0>
<div class="info-panel">
<h3>📊 Access Log</h3>
<cfloop array="#accessLog#" index="entry">
<div style="padding: 10px; background: ##f8f9fa; border-radius: 5px; margin-bottom: 10px;">
<cfoutput>
<strong>#dateTimeFormat(entry.timestamp, "HH:nn:ss")#</strong> -
#entry.docTitle# (#entry.docId#) -
<strong style="color: ##3498db;">#entry.action#</strong> -
Disposition: <code>#entry.disposition#</code>
</cfoutput>
</div>
</cfloop>
</div>
</cfif>
</div>
</body>
</html>