ColdFusion 9.0 Resources |
cffile action = "readBinary"Note: You can specify this tag’s attributes
in an attributeCollection attribute whose value
is a structure. Specify the structure name in the attributeCollection attribute
and use the tag’s attribute names as structure keys.
DescriptionReads a binary file (such as an executable or image file) on the server, into a binary object parameter that you can use in the page. To send it through a web protocol (such as HTTP or SMTP) or store it in a database, first convert it to Base64 using the ToBase64 function. Note: This action reads the file into a variable in
the local Variables scope. It is not intended for use with large
files, such as logs, because they can bring down the server.
Attributes
UsageYou convert the binary file to Base64 to transfer it to another site. ColdFusion supports reading an image file as a binary and passing the result to a cfimage, for example: <!--- Convert a JPG image to a binary object. ---> <cffile action="readBinary" file="maxwell05.jpg" variable="binaryObject"> <!--- Create a cfimage from the binary object variable. ---> <cfset myImage=ImageNew(binaryObject)> ExampleThe following example reads the binary file somewhere.jpg, writes it to a different folder as somewhereB.jpg, and then displays the new file: <cffile action = "readBinary" file = "C:\inetpub\wwwroot\cfdocs\getting_started\photos\somewhere.jpg" variable = "aBinaryObj"> <!--- Output binary object to JPEG format for viewing. ---> <cffile action="write" file = "c:\files\updates\somewhereB.jpg" output = "#toBinary(aBinaryObj)#"> <!--- HTML to view image. ---> <img src="C:\files\updates\somewhereB.jpg"> |