Display thumbnailPhoto from Active Directory in PHP

后端 未结 3 1025
予麋鹿
予麋鹿 2020-12-01 17:22

I\'ve set up a system to display everyone\'s name, email address and phone number from Active Directory however I can\'t get the \'thumbailPhoto\' to work.

I have se

相关标签:
3条回答
  • 2020-12-01 17:36

    when you store the photo data into ldap i.e. "jpegphoto" attribute it should be done by using encode base64. Reading the attribute is already decoded on fly. Hence I would use something less modified code

    $tempFile = tempnam(sys_get_temp_dir(), 'image');
    file_put_contents($tempFile, $imageString);
    $finfo = new finfo(FILEINFO_MIME_TYPE);
    $mime  = explode(';', $finfo->file($tempFile));
    header("Content-Type: $mime");
    echo $imageString;
    

    This is direct php image write example you can directly use it under tag img i.e.

    <img src="example.php" />
    
    0 讨论(0)
  • 2020-12-01 17:44

    This seems to be a JPEG-File, so you should be able to send that data together with the appropriate mime-type to the browser. It should be possible to output that image with something like:

    <img src="data:image/jpeg;base64,<?php echo base64_encode($imageString); ?>"/>
    

    But it might also be possible to save files of any image format into that thumbnailPhoto attribute. Therefore, I would put the content into a temporary file that will then be served directly from the server. You will need to pass the file through finfo to get the correct mime-type.

    So you might do something like this:

    $tempFile = tempnam(sys_get_temp_dir(), 'image');
    file_put_contents($tempFile, $imageString);
    $finfo = new finfo(FILEINFO_MIME_TYPE);
    $mime  = explode(';', $finfo->file($tempFile));
    echo '<img src="data:' . $mime[0] . ';base64,' . base64_encode($imageString) . '"/>';
    
    0 讨论(0)
  • 2020-12-01 17:44

    Try the code below. It is an adaptation of the answer above.

    <?php $result = ldap_search($ad , $dn , $filter, $attributes); $aduser = ldap_get_attributes($ad, ldap_first_entry($ad,$result)); ?>

    <img src="data:image/jpeg;base64,<?php echo base64_encode($aduser['thumbnailPhoto'][0]); ?>" />
    
    0 讨论(0)
提交回复
热议问题