我有这段代码:
if (TRUE === ldap_bind($ldap_connection, $ldap_username, $ldap_password)){
$ldap_base_dn = 'DC=xx,dc=xx,dc=xx';
$search_filter = '(&(objectCategory=person)(samaccountname=*))';
$attributes = array();
$attributes[] = 'givenname';
$attributes[] = 'mail';
$attributes[] = 'samaccountname';
$attributes[] = 'ipphone';
$attributes[] = 'thumbnailPhoto';
$result = ldap_search($ldap_connection, $ldap_base_dn, $search_filter, $attributes);
if (FALSE !== $result){
$entries = ldap_get_entries($ldap_connection, $result);
for ($x=0; $x<$entries['count']; $x++){
if (!empty($entries[$x]['givenname'][0]) &&
!empty($entries[$x]['mail'][0]) &&
!empty($entries[$x]['samaccountname'][0]) &&
!empty($entries[$x]['ipphone'][0]) &&
'Shop' !== $entries[$x]['ipphone'][0] &&
'Account' !== $entries[$x]['ipphone'][0]){
$ad_users[strtoupper(trim($entries[$x]['samaccountname'][0]))] = array('email' => strtolower(trim($entries[$x]['mail'][0])),'first_name' => trim($entries[$x]['givenname'][0]),'phone' => trim($entries[$x]['ipphone'][0]), 'photo' => trim ($entries[$x]['thumbnailPhoto'][0]));
}
}
}
ldap_unbind($ldap_connection);
}
echo json_encode($ad_users);
我只获得了thumbnailPhoto的null。
如何处理这类数据?我可以得到这张照片的网址吗? 我正在开发iOS应用程序并使用json在php中发送员工数据但是如何将这个thumbnailPhoto也发送给json中的每个员工?
答案 0 :(得分:0)
您必须使用属性'thumbnailphoto'而不是'thumbnailPhoto'(没有大写字母)。 然后在你的$ ad_users数组中,你必须转换为base64 insted of trim:
'photo' => base64_encode ($entries[$x]['thumbnailPhoto'][0])