I am trying to update a bunch of user photos in our Windows Active Directory using PHP and ldap_modify. 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? By default Outlook, etc. looks at the thumbnailPhoto
attribute, which is just a byte array of the file (not base64 encoded). Something like this:
$changes['thumbnailPhoto'] = $data;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.