Force push file to user dynamically


/ Published in: ColdFusion
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <cfsetting showdebugoutput="yes">
  2.  
  3. <Cfset personnel.jobtitle = "Webmaster">
  4. <cfset personnel.location = "The dungeon">
  5. <cfset personnel.skills = "Can program and stuff">
  6. <cfset personnel.name = "Bob Jones">
  7.  
  8. <cfset thisPath = ExpandPath("*.*")>
  9. <cfset thisDirectory = GetDirectoryFromPath(thisPath)>
  10.  
  11. <!--- Get the RTF data from the base file --->
  12. <Cffile action="read" file="#thisDirectory#\pagepart.txt" variable="PagePart">
  13.  
  14. <!--- Replace the placeholders with data --->
  15. <Cfset pagePart = replacenocase(pagepart, '~~~recordFor~~~', 'Bob Jones') >
  16. <Cfset pagePart = replacenocase(pagepart, '~~~jobtitle~~~', 'Devision Head') >
  17. <Cfset pagePart = replacenocase(pagepart, '~~~workLocation~~~', 'Office') >
  18. <Cfset pagePart = replacenocase(pagepart, '~~~skills~~~', 'Management') >
  19.  
  20. <!--- Get the image and convert to Hex --->
  21. <cffile action="readbinary" file="#thisDirectory#\please_buy_cookies.jpg" variable="getImage">
  22. <Cfset getImage = binaryencode(getImage, 'hex') >
  23.  
  24. <!--- Replace image placeholder with image data --->
  25. <Cfset pagePart = replacenocase(pagepart, '~~~image~~~', getImage) >
  26.  
  27. <!--- Push to the users computer as if they asked to download a file. --->
  28. <cfheader name="Content-Disposition" value="attachment; filename=test.rtf">
  29. <CFCONTENT TYPE="application/rtf" ><CFOUTPUT>#pagePart#</CFOUTPUT>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.