Skip to content

Instantly share code, notes, and snippets.

@timcunningham
Last active December 11, 2020 20:06
Show Gist options
  • Save timcunningham/abff45f78afbe5925711f033b92c4275 to your computer and use it in GitHub Desktop.
Save timcunningham/abff45f78afbe5925711f033b92c4275 to your computer and use it in GitHub Desktop.
docfetcher
<cfscript>
param name="url.document" default="";
param name="statusText" default="";
// Get document path. Replace backslashes in url.document with forward slashes for OS consistency
documentPath = settings.batchDirectory & "/" & url.document.replace("\", "/", "all");
// Respond with 404 if the document does not exist on disk
if (! url.document.len() || ! fileExists(documentPath)) {
response.statusCode = 404;
response.statusText = "NotFound";
response.body.error = "File not found";
}
// Otherwise process the document for response
else {
document = fileRead(documentPath);
response.statusCode = 200;
}
// Echo back the success and file content
response.body.success = fileExists(documentPath) ? true : false;
response.body.html =fileExists(documentPath) ? document : "";
response.body.file = "";
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment