如何使用PHP ldap_modify更新Active Directory中的照片

时间:2019-02-21 23:38:28

标签: php active-directory ldap

我正在尝试使用PHP和ldap_modify更新Windows Active Directory中的大量用户照片。我没有收到任何错误,但照片也未更新。有什么不对劲的地方我做错了吗?

<?php
//previously have connected to AD and have $conn resource. I also have correct $dn.
$photofile='/var/www/temp/mynewphoto.jpg';
$data=file_get_contents($photofile);
$changes['photo']='data:image/jpeg;base64,'.base64_encode($data);
if(!ldap_modify($conn, $dn, $changes)){
    $enum=ldap_errno($conn);
    $msg=ldap_err2str( $enum );
    echo "Photo change Failed for {$dn}. {$msg}".'<br />'.PHP_EOL.printValue($ldapInfo);
}
else{               
    echo "Photo Updated for  : {$dn} : {$rec['dn']}<br />".PHP_EOL;
    $cnt+=1;
}

2 个答案:

答案 0 :(得分:1)

确定要使用photo属性吗?默认情况下,Outlook等会查看thumbnailPhoto属性,该属性只是文件的字节数组(未进行base64编码)。像这样:

$changes['thumbnailPhoto'] = $data;

答案 1 :(得分:1)

<?php
//previously have connected to AD and have $conn resource. I also have correct $dn.
$photofile='/var/www/temp/mynewphoto.jpg';
$data=file_get_contents($photofile);
$changes= ['thumbnailPhoto' => [$data]];
if(!ldap_modify($conn, $dn, $changes)){
    $enum=ldap_errno($conn);
    $msg=ldap_err2str( $enum );
    echo "Photo change Failed for {$dn}. {$msg}".'<br />'.PHP_EOL.printValue($ldapInfo);
}
else{               
    echo "Photo Updated for  : {$dn} : {$rec['dn']}<br />".PHP_EOL;
    $cnt+=1;
}