Creating a Download Page in ColdFusion 8

I have an application that allows administrators to upload files. These files are stored outside the root website, so they are not accessible through the URL. Previously, we always used a code similar to the one below to then transfer the file to authorized users. Is there a better or more universal way to specify a type? This is especially true when administrators can upload many different types of files.

<cfheader name="content-disposition" value="filename=#queryname.filename#"> <cfcontent type="application/unknown" file="#application.pathToDataDirectory#/#queryname.filename#"> 
+7
coldfusion mime-types download
source share
2 answers

As far as I know, I do not think that there is a real "mime-type" written in any kind of file. This is just what gives the browser a warning about what is happening in its path.

Several smart mime-type functions are mentioned here (note the second comment). I have not tried them, but they should fit your needs: http://www.coldfusionmuse.com/index.cfm/2006/8/2/mime.types

If you want to write your own smart mime-type function, you can easily convert this PHP function to ColdFusion: http://snipplr.com/view/11451/get-file-mimetype/

+6
source share

Somewhat late, but why donโ€™t you capture and save the MIME type when downloading the file? <cffile> returns it in cffile.contentType and cffile.contentSubType , so it is not absolutely burdensome. Of course, you will need to run the scan on existing files, but this is just a one-line script.

FWIW, my file upload code also sends the file size and the modified date and checks for repeated requests for unmodified files. All this after authentication / authorization, of course:

 <cfset modified=parsedatetime(queryname.datestamp)/> <cfif structkeyexists(cgi, "http_if_modified_since")> <cfif parsedatetime(cgi.http_if_modified_since) gt modified> <cfheader statuscode=304 statustext="Not modified"/> <cfabort/> </cfif> </cfif> <cfheader name="Content-Disposition" value='disposition=#disposition#; filename="#queryname.filename#"'/> <cfheader name="Content-Length" value=#queryname.size#/> <cfheader name="Last-Modified" value=#gethttptimestring(modified)#/> <cfcontent type=#queryname.mimetype# file="application.pathToDataDirectory/#queryname.filename#"/> 
+1
source share

All Articles