<html>
<head>
<link href="mmres://user_interface_reference.css" rel="stylesheet" type="text/css">
<title>TOBASE64</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
   <div id="Description">
   <table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
      <tr> 
         <td valign="top" class="name">TOBASE64</td>
         <td valign="top" nowrap class="compatibility">&nbsp;</td>
      </tr>
      <tr>
         <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
      </tr>


    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Description</span>
<p>
Calculates the Base64 representation of a string or binary object. The Base64 format uses printable characters, allowing binary data to be sent in forms and e-mail, and stored in a database or file.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Returns</span>
<p>
The Base64 representation of a string or binary object. 
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Category</span>
<p>
Conversion functions, String functions
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Function syntax</span><pre>ToBase64(string or binary_object[, encoding])
</pre>    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">See also</span><ul>

<li>BinaryEncode for converstion of binary data to base64</li>

<li>cffile for information about loading and reading binary data</li>

<li>cfwddx for information about serializing and deserializing binary data</li>

<li>IsBinary and ToBinary for checking for binary data and converting a Base64 object to binary format</li>
</ul>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">History</span>
<p>
ColdFusion&#160;MX: Added the encoding parameter.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Parameters</span>
<p>

</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Usage</span>
<p>
Macromedia recommends that you use the BinaryEncode function to convert binary data to Base64-encoded data in all new applications. 
</p>
<pre>&lt;h3&gt;ToBase64 Example&lt;/h3&gt;
&lt;!--- Initialize data. ----&gt;
&lt;cfset charData = &quot;&quot;&gt;
&lt;!--- Create string of ASCII characters (32-255); concatenate them ---&gt;
&lt;cfloop index = &quot;data&quot; from = &quot;32&quot; to = &quot;255&quot;&gt;
   &lt;cfset ch = chr(data)&gt;
   &lt;cfset charData = charData &amp; ch&gt;
&lt;/cfloop&gt;
&lt;p&gt;
The following string is the concatenation of all characters (32 to 255) 
from the ASCII table.&lt;br&gt;
&lt;cfoutput&gt;#charData#&lt;/cfoutput&gt;
&lt;/p&gt;
&lt;!--- Create a Base64 representation of this string. ----&gt;
&lt;cfset data64 = toBase64(charData)&gt;

&lt;!----- Convert string to binary. -------&gt;
&lt;cfset binaryData = toBinary(data64)&gt;
&lt;!--- Convert binary back to Base64. ----&gt;
&lt;cfset another64 = toBase64(binaryData)&gt;
&lt;!---- Compare another64 with data64 to ensure that they are equal. ----&gt;
&lt;cfif another64 eq data64&gt;
   &lt;h3&gt;Base64 representations are identical.&lt;/h3&gt;
&lt;cfelse&gt;
   &lt;h3&gt;Conversion error.&lt;/h3&gt;
&lt;/cfif&gt;
</pre>
         </td>
      </tr>
   </table>
   </div>
<div id="STRING OR BINARY_OBJECT">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">STRING OR BINARY_OBJECT</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>


<p>A string, the name of a string, or a binary object.</p>

  </td>
  </tr>
  </table>
</div>
<div id="ENCODING ">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">ENCODING </td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>


<p>For a string, defines how characters are represented in a byte array. The following list includes commonly used values:</p><ul>

<li>utf-8</li>

<li>iso-8859-1 </li>

<li>windows-1252</li>

<li>us-ascii</li>

<li>shift_jis</li>

<li>iso-2022-jp </li>

<li>euc-jp</li>

<li>euc-kr</li>

<li>big5</li>

<li>euc-cn</li>

<li>utf-16</li>
</ul>

<p>For more information on character encoding, see:www.w3.org/International/O-charset.html</a>. </p>
<p>The default value is the encoding of the page on which the function is called. See cfcontent. For a binary object, this parameter is ignored.</p>

  </td>
  </tr>
  </table>
</div>

  </body>
</html>
