I have an application that allows admins to upload files. These files are stored outside of the web root so they are not accessible via a URL. In the past, we have always used code similar to below to then serve the file back to authorized users. Is there a better or more universal way to specify the type? This is especially relevant when admins are allowed to upload many different types of files.
<cfheader name="content-disposition" value="filename=#queryname.filename#">
<cfcontent type="application/unknown" file="#application.pathToDataDirectory#/#queryname.filename#">
As far as I know, i don’t think that there is an actual “mime-type” written into any kind of file. It’s just something that gives the browser a warning about what’s coming its way.
Several “smart mime-type” functions are mentioned here (note the second comment as well). I have not tried these, but they should suit your needs: http://www.coldfusionmuse.com/index.cfm/2006/8/2/mime.types
If you wanted to write your own “smart mime-type” function, you could easily convert this PHP function into ColdFusion: http://snipplr.com/view/11451/get-file-mimetype/