通过 PHP 设置缩略图属性

发布于 2024-12-18 09:04:20 字数 283 浏览 1 评论 0原文

在我的工作中,我们最近升级到 Lync(办公通讯器的精美版本),并且有一个照片字段可以在电子邮件和聊天中显示您的照片。

问题是,这个“默认公司图片”存储在用户帐户的活动目录对象中的thumbnailPhoto 属性中。

使用 ADSI,我可以设置不同的值,但不幸的是,就更新这张照片而言,除了 .NET 之外,我在网上找不到任何东西。

我已经在 PHP 和 Active Directory 中完成了其他工作,如果有人能够通过 PHP 设置这张照片,我很想看看您是如何做到的。

提前致谢!

At my work we recently upgraded to Lync ( fancy version of office communicator ) and there is a photo field that will display your photo on email and chat.

The problem is, this "default corporate picture" is stored in the active directory object for the user account within the thumbnailPhoto attribute.

Using ADSI I'm allowed to play with setting different values but unfortunately I can't find anything on the net except .NET stuff as far as updating this photo goes.

I've done other stuff in PHP and Active Directory, if anyone has been able to set this photo via PHP I'd love to see how you did it.

THanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

停顿的约定 2024-12-25 09:04:20

我在谷歌上搜索了这个问题的解决方案。
由于我找不到任何适合我需求的东西,所以我分享我的解决方案。

属性 image 是包含图像的 base64 字符串。

if(!isset($_POST["username"]))
    exit(json_encode(array("error" => true, "errormsg" => "No username attr set")));
$username = preg_replace("[^a-zA-Z0-9]", "", $_POST["username"]);

if(!isset($_POST["image"]))
    exit(json_encode(array("error" => true, "errormsg" => "No image attr set")));
$image = base64_decode($_POST["image"]);

// Set LDAP Information
$ds = ldap_connect("ldap://IP_ADDRESS");
$r = ldap_bind($ds, "DOMAIN\USERNAME", "PASSWORD");

// Search for UPN in given OU
$search = "(&(objectCategory=user)(objectClass=user)(userPrincipalName=$username))";
$sr = ldap_search($ds, "OU=OU_NAME,DC=DC_NAME,DC=local", $search);
$data = ldap_get_entries($ds, $sr);

if($data["count"] == 1){
    // OPTIONAL: Show existing image
    /*echo "<strong>Distinguished Name: </strong>" . $data[0]["dn"] . "<br />";
    if (isset($data[0]["thumbnailphoto"]) && isset($data[0]["thumbnailphoto"][0])) {
        echo '<img src="data:image/jpeg;base64,' . base64_encode($data[0]["thumbnailphoto"][0]) . '" height=200/><br>';
    }
    else {
        echo "<strong>Photo not set</strong><br />";
    }*/

    if(ldap_mod_replace($ds, $data[0]["dn"], array("thumbnailPhoto" => $image))){
        exit(json_encode(array("error" => false, "errormsg" => "thumbnailphoto for user $username was set")));
    }else{
        exit(json_encode(array("error" => true, "errormsg" => "thumbnailphoto for user $username could not be set")));
    }
}elseif($data["count"] == 0){
    exit(json_encode(array("error" => true, "errormsg" => "No user found for $username")));
}elseif($data["count"] > 1){
    exit(json_encode(array("error" => true, "errormsg" => "Multiple users found for $username")));
}
ldap_close($ds);

I searched on google for a solution for this problem.
Since I couldn't find anything that fitted my needs i am sharing my solution.

The attribute image is a base64 string that contains the image.

if(!isset($_POST["username"]))
    exit(json_encode(array("error" => true, "errormsg" => "No username attr set")));
$username = preg_replace("[^a-zA-Z0-9]", "", $_POST["username"]);

if(!isset($_POST["image"]))
    exit(json_encode(array("error" => true, "errormsg" => "No image attr set")));
$image = base64_decode($_POST["image"]);

// Set LDAP Information
$ds = ldap_connect("ldap://IP_ADDRESS");
$r = ldap_bind($ds, "DOMAIN\USERNAME", "PASSWORD");

// Search for UPN in given OU
$search = "(&(objectCategory=user)(objectClass=user)(userPrincipalName=$username))";
$sr = ldap_search($ds, "OU=OU_NAME,DC=DC_NAME,DC=local", $search);
$data = ldap_get_entries($ds, $sr);

if($data["count"] == 1){
    // OPTIONAL: Show existing image
    /*echo "<strong>Distinguished Name: </strong>" . $data[0]["dn"] . "<br />";
    if (isset($data[0]["thumbnailphoto"]) && isset($data[0]["thumbnailphoto"][0])) {
        echo '<img src="data:image/jpeg;base64,' . base64_encode($data[0]["thumbnailphoto"][0]) . '" height=200/><br>';
    }
    else {
        echo "<strong>Photo not set</strong><br />";
    }*/

    if(ldap_mod_replace($ds, $data[0]["dn"], array("thumbnailPhoto" => $image))){
        exit(json_encode(array("error" => false, "errormsg" => "thumbnailphoto for user $username was set")));
    }else{
        exit(json_encode(array("error" => true, "errormsg" => "thumbnailphoto for user $username could not be set")));
    }
}elseif($data["count"] == 0){
    exit(json_encode(array("error" => true, "errormsg" => "No user found for $username")));
}elseif($data["count"] > 1){
    exit(json_encode(array("error" => true, "errormsg" => "Multiple users found for $username")));
}
ldap_close($ds);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文