murp

Force Filedownload ColdFusion

Jun 28th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <cfset variables.filepath = ExpandPath('myfolder') & variables.myfile />
  2.  
  3. <cfswitch expression="#LCase(ListLast(variables.myfile, "."))#">
  4.   <cfcase value="avi">
  5.     <cfset variables.contentType = "video/x-msvideo" />
  6.   </cfcase>
  7.   <cfcase value="doc">
  8.     <cfset variables.contentType = "application/msword" />
  9.   </cfcase>
  10.   <cfcase value="exe">
  11.     <cfset variables.contentType = "application/octet-stream" />
  12.   </cfcase>
  13.   <cfcase value="gif">
  14.     <cfset variables.contentType = "image/gif" />
  15.   </cfcase>
  16.   <cfcase value="jpg,jpeg">
  17.     <cfset variables.contentType = "image/jpg" />
  18.   </cfcase>
  19.   <cfcase value="mp3">
  20.     <cfset variables.contentType = "audio/mpeg" />
  21.   </cfcase>
  22.   <cfcase value="mov">
  23.     <cfset variables.contentType = "video/quicktime" />
  24.   </cfcase>
  25.   <cfcase value="mpe,mpg,mpeg">
  26.     <cfset variables.contentType = "video/mpeg" />
  27.   </cfcase>
  28.   <cfcase value="pdf">
  29.     <cfset variables.contentType = "application/pdf" />
  30.   </cfcase>
  31.   <cfcase value="png">
  32.     <cfset variables.contentType = "image/png" />
  33.   </cfcase>
  34.   <cfcase value="ppt">
  35.     <cfset variables.contentType = "application/vnd.ms-powerpoint" />
  36.   </cfcase>
  37.   <cfcase value="wav">
  38.     <cfset variables.contentType = "audio/x-wav" />
  39.   </cfcase>
  40.   <cfcase value="xls">
  41.     <cfset variables.contentType = "application/vnd.ms-excel" />
  42.   </cfcase>
  43.   <cfcase value="zip">
  44.     <cfset variables.contentType = "application/zip" />
  45.   </cfcase>
  46.   <cfdefaultcase>
  47.     <cfset variables.contentType = "application/unknown" />
  48.   </cfdefaultcase>
  49. </cfswitch>
  50.  
  51. <cfheader name="Content-disposition" value="attachment;filename=#variables.myfile#" />
  52. <cfcontent type="#variables.contentType#" file="#variables.filepath#" />
Add Comment
Please, Sign In to add comment