[英]How to update photo in Active Directory using PHP ldap_modify
I am trying to update a bunch of user photos in our Windows Active Directory using PHP and ldap_modify.我正在尝试使用 PHP 和 ldap_modify 在我们的 Windows Active Directory 中更新一堆用户照片。 I get no errors but the photo is not updated either.
我没有收到任何错误,但照片也没有更新。 Anything glaring that I am doing wrong?
有什么明显的我做错了吗?
<?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;
}
<?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;
}
Are you sure you want the photo
attribute?您确定要
photo
属性吗? By default Outlook, etc. looks at the thumbnailPhoto
attribute, which is just a byte array of the file (not base64 encoded).默认情况下,Outlook 等查看
thumbnailPhoto
属性,它只是文件的字节数组(不是base64 编码的)。 Something like this:像这样的东西:
$changes['thumbnailPhoto'] = $data;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.