title: Viewing jpeg from LDAP via PHP
body: <p>I store contacts photo in openLDAP. All works fine, but i cant get jpegPhoto in base64 format (like ldapsearch output it) with PHP.</p>
  
  <p>Part of ldapsearch -x: </p>
  
  <pre><code>*# 1486, People, domain.name
  dn: uidNumber=0000,ou=People,dc=domain,dc=name
  objectClass: someUnit
  uidNumber: 0000
  gidNumber: 0000
  loginShell: /bin/false
  cn:: Anon
  roomNumber:: 000
  telephoneNumber: 00-00-00 00-00
  departmentNumber:: 000
  jpegPhoto:: /9j/4AAQSkZJRgABAQEAtAC0AAD/4QzsRXhpZgAASUkqAAgAAAAIAA4BAgAgAAAAbg
   AAAA8BAgAGAAAAjgAAABABAgAPAAAAlAAAADIBAgAUAAAApAAAABMCAwABAAAAAgCaOwEQAwABAAA
   A4BAAAAIQAwABAAAAqAwAAGmHBAABAAAAuAAAAAAAAAAgICAgICAgICAgICAgICAgICAgICAgICAg
   ICAgICAgAENhbm9uAENhbm9uIElYVVMgMTMwAAAyMDExOjAyOjE3IDE0OjU3OjE5AB8AmoIFAAEAA
   AAyAgAAnYIFAAEAAAA6AgAAJ4gDAAEAAACQAc3/AJAHAAQAAAAwMjIxA5ACABQAAABCAgAABJACAB
   QAAABWAgAAAZEHAAQAAAABAgMAApEFAAEAAABqAgAAAZIKAAEAAAByAgAAApIFAAEAAAB6AgAABJI
   KAAEAAACCAgAABZIFAAEAAACKAgAAB5IDAAEAAAAFAEH/CZIDAAEAAAAYAED/CpIFAAEAAACSAgAA
   .............................................................................
  </code></pre>
  
  <p>PHP code for data output:</p>
  
  <pre><code>$ds = ldap_connect('localhost', 389)
            or die("Невозможно соединиться с $ldaphost");
  $justthese = array("cn", "roomNumber", "telephoneNumber","departmentNumber","mail","jpegPhoto");
  $sr=ldap_search($ds, $dn, $filter, $justthese);
  $entry = ldap_get_entries($ds, $sr);
  $i=0;
  
  //Formation of the table header
  
  ..............................................................
  
  do {
  
      $matches = "";
  
  // Output "cn", "roomNumber", "telephoneNumber","departmentNumber"
  
      echo "&lt;td style=\"border-right:1px solid lightgray; \" align=\"center\"&gt;".$entry[$i]["departmentnumber"][0]."&lt;/td&gt;";
      echo "&lt;td style=\"padding-left:20px;\"&gt;&lt;a href=\"mailto:".$entry[$i]["mail"][0]."\"&gt;".$entry[$i]["mail"][0]."&lt;/a&gt;&lt;/td&gt;";
      echo "&lt;/tr&gt;";
  
      echo $entry[$i]["jpegphoto"][0];
  
  
      $i++;
  } while ($i&lt;count($entry)-1);
  echo "&lt;/table&gt;";
  
  ldap_close($ds);
  </code></pre>
  
  <p>I want to get base64 $entry[$i]["jpegphoto"][0] equal: "/9j/4AAQSkZJRgABAQEAtAC0AAD/4QzsRXhpZgAASUkqAAgAAAAIAA4BAgAgAAAAbgAAAA8BAgAGAAAAjgAAABABAgAPAAAAlAAAADIBAgAUAAAApAAAABMCAwABAAAAAgCaOwEQAwABAAA..."</p>
  
  <p>But I result is:<br>
  "����JFIF�����ExifII* n��2��;��i�� CanonCanon IXUS 1302011:02:16 10:51:57��2��:'���0221�B�V��j� r�z� ����  �Y ��|�*  �����0100����������r^�#&amp;�$'&amp;�! �!������KH2 2011:02:16 10:51:572011:02:16 10:51:57� � � =�04��"���b      , �L�&amp;1�Zbb    E�   "� #�'    �(��-.�/�<code>��@��� N������ ���������=��D�z���</code>�� �IMG:IXUS 130 JPEGFirmware Version 1.00����Q����������?  (p1p�@1p g����,�<code>F�</code>F����Fz�?)�EW���@p����@>���������������������������������������������������Q8,���� ���@p�O������� �2_b    ��@�R555����R5<code>5</code>5��$�)5: F&amp;5( ��������Xh�                ""     $'))'$ #(,--,( <em>.//.</em> <em>.//.</em>% (,--,(#  $'))'$    ""          ����pc�b���q��������"@u���II*��A�@p1�����C             ��C      ����"��  ���}!1AQa"q2���#B��R��$3br� "</p>