]> git.sur5r.net Git - openldap/blob - contrib/php3-tool/ldap-photo.php3
fixed test on "" (empty) parent dn
[openldap] / contrib / php3-tool / ldap-photo.php3
1 <?
2 if (isset($base_dn)) {
3 //      echo urldecode ($base_dn)."<br>\n";
4 }
5 if (isset($cn)) {
6 //      echo urldecode ($cn)."<br>\n";
7 }
8 $link_identifier = ldap_connect("127.0.0.1");
9 $result_identifier = ldap_read($link_identifier, $base_dn, 'objectclass=*');
10 if(!$result_identifier) {
11         echo "No results.\n";
12 }
13 else {
14         $num_entries = ldap_count_entries($link_identifier, $result_identifier);
15         if ($num_entries == 0) {
16                 echo "No results\n";
17                 return 1;
18         }
19         Header("Content-type: image/jpeg");
20         $info = ldap_get_entries($link_identifier, $result_identifier);
21         ldap_close($link_identifier);
22         for ($i=0; $i<$info["count"]; $i++) {
23 //              echo $i;
24                 if ($info[$i]["cn"][0] == $cn) {
25                         //echo "<b>".$info[$i]["cn"][0]."</b><br>";
26                 }
27                 for ($j=0; $j<$info[$i]["count"]; $j++) {
28                         $attribute = $info[$i][$j];
29                         if (strtolower ($attribute) == "jpegphoto") {
30                         //      $file = fopen("/tmp/tmpphoto.jpg", "w");
31                         //      echo $info[$i]["jpegphoto"][0];
32                                 $p = $info[$i]["jpegphoto"][0];
33                                 $photo = base64_decode($p);
34                                 echo $photo;
35                         //      fwrite($file, $photo);
36                         //      flush();
37                         //      fclose($file);
38                         //      $file = fopen("/tmp/tmpphoto.jpg", r);
39                         //      $contents = fread ($file, filesize("/tmp/tmpphoto.jpg"));
40                         //      fclose($file);
41                         //      echo $contents;
42                         }
43                 }
44         }
45 }
46 ?>