如何从活动目录获得thumbnailPhoto ?php


How to get thumbnailPhoto from Active Directory ? php

我有这样的代码:

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

如何处理这类数据?我能得到这张照片的url吗?我正在开发iOS应用程序,并在php中使用json发送员工数据,但我如何发送此thumbnailPhoto也与json中的每个员工?

你必须使用属性'thumbnailphoto'而不是'thumbnailphoto'(没有大写字母)。然后在$ad_users数组中你必须转换为base64而不是trim:

'photo' => base64_encode ($entries[$x]['thumbnailPhoto'][0])