Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8137191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:01:15+00:00 2026-06-06T11:01:15+00:00

I’m creating an application for our office that allows authenticated users in the office

  • 0

I’m creating an application for our office that allows authenticated users in the office to upload files for clients, creates a list of links to download the files and emails the client with the list of links.

When a user in the office logs in they’re assigned a UUID in their session scope. That UUID becomes the directory name that the uploaded files are stored in.

Occasionally I’ll need to clear out old files and delete the directories, but when that happens there’s a chance a client may try to re-download a file from an old link.

In ColdFusion 9 how would I catch this and send them to an error page? I’m also hoping to use similar code to redirect a user once the download starts so they’re not just sitting on a blank page during the download process.

Here’s my force download page that takes a folder name variable and a filename variable to serve up the files.

<cfset folder = #URL.folder#>
<cfset FileDownload = #URL.file#>

<cfset exten = ListLast(FileDownload, ".")>

<cfswitch expression="#exten#">
<cfcase value="zip"><cfset content_type = "application/zip, application/x-zip, application/x-zip-compressed, application/octet-stream, application/x-compress, application/x-compressed, multipart/x-zip"></cfcase>
<cfcase value="ai"><cfset content_type = "application/illustrator"></cfcase>
<cfcase value="eps"><cfset content_type = "application/illustrator, application/octect-stream"></cfcase>
<cfcase value="pdf"><cfset content_type = "application/pdf, application/x-pdf, application/acrobat, applications/vnd.pdf, text/pdf, text/x-pdf"></cfcase>
<cfcase value="psd"><cfset content_type = "image/photoshop, image/x-photoshop, image/psd, application/photoshop"></cfcase>
<cfcase value="jpg"><cfset content_type = "image/jpeg"></cfcase>
<cfcase value="png"><cfset content_type = "image/png"></cfcase>
<cfcase value="tif"><cfset content_type = "image/tiff"></cfcase>
<cfdefaultcase><cfset content_type = "image/jpeg"></cfdefaultcase>
</cfswitch>

<cfset fileToGetSizeOf = expandPath("./#folder#/#FileDownload#") />


<cfoutput><cfheader name="content-disposition" value="attachment;filename=#FileDownload#"><cfheader name="content-length" value="#getFileInfo(fileToGetSizeOf ).size#" />
<cfcontent type="#content_type#" file="#ExpandPath("./#folder#")#/#FileDownload#" deletefile="#delete_file#"></cfoutput>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T11:01:18+00:00Added an answer on June 6, 2026 at 11:01 am

    There are three goals you want to achieve here:

    1. Serve the files securely. Currently you are not protected from exploiting the system (or other user) files, for example like this (I’ve set passed values instead of URL keys):

      <cfset folder = "../../../some/other/path/" />
      <cfset FileDownload = "some_other_file.pdf" />
      
    2. Show 404 page if file or directory does not exist any more.

    3. Show some nice page once download starts. Maybe I am missing something, but redirecting user after download started (=headers are sent) is pretty tricky.

    Any way, there’s pretty simple and reliable solution to all of these.

    You should keep the list of the files in database, so each record may include:

    1. Unique ID.
    2. File owner ID.
    3. Directory name.
    4. File name.
    5. Description (optional, you can use filename).
    6. Content type (optional, you still can use approach with extension).
    7. Created date (optional, can be used for scheduled cleaning).
    8. Downloads counter (optional, if you want to limit downloads count).
    9. Status (optional, can be used to prevent filesystem checks for deleted files).

    Note: 3-4 may be done as single column (‘path/filename.ext’) since paths are temporary any way.

    So, when your application creates a list of links to download the files and emails the client with the list of links., it also records each file to the database. Each of these links now may look like this:

    <a href="http://yourwebsite.tld/download.cfm?file=#ID#">#DESCRIPTION#</a>
    

    When user clicks the link script performs following:

    1. Check if ID exists in DB. If not — redirect to 404 page.
    2. Check if current user matches the owner ID. If not — redirect to 404 page.
    3. Check file status, downloads counter (if needs to be limited). If not — redirect to 404 page.
    4. Check actual file existence using stored directory and filename. If not — redirect to 404 page.
    5. IF there’s a start key in URL: increment the downloads counter, serve the file using cfcontent and content type.
    6. ELSE render the HTML of the page saying “Download will start momentarily, click this link if you don’t want to wait” where link looks like download.cfm?file=#ID#&start=yes, plus you have meta http-equiv="refresh" with same URL.

    Notes:

    1. Steps 1-4 may be wrapped in single try/catch block with custom errorCode, so you can have one place of redirect.
    2. Trick with step 5 here is that user will stay on the page when clicks the Download link, and wont see blank page. This is not exact solution for goal #3, but it would be hard to make something better without some trickery. Maybe I am wrong and someone could suggest better way here, it’d be cool. You can remove the “Click this link part” to make this page look “natural”.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.