February 12, 2008

ColdFusion CFLDAP - Display images stored in Microsoft Active Directory

Not too hard once I found out how MS stores the data in the photoJpeg field of Active Directory.

<!--- imageFile.cfm --->
<cfsilent>
<cfldap action="QUERY"
name="ldap"
attributes="jpegPhoto"
start="dc=[yourdc],dc=com"
filter="sAMAccountName=[loginname]"
server="[yourserver]"
username="[username]"
password="[password]">
<cfscript>
     ldapPhoto = toString(ldap.jpegPhoto);
     ldapPhoto = binaryDecode(ldapPhoto,"base64");
</cfscript>
</cfsilent><cfcontent type="image/jpeg" variable="#ldapPhoto#">


<!--- to display the image on a page --->
<img src="imageFile.cfm" width="100" height="125" alt="">





No comments: