PHP 4.0 Bug #5759: Unable to add binary data to LDAP
| From: | johan dot troedsson at ei dot sigma dot se | Date: | Mon, 24 Jul 2000 14:07:47 +0000 |
| Subject: | PHP 4.0 Bug #5759: Unable to add binary data to LDAP | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-25713@lists.php.net to get a copy of this message | ||
From: johan.troedsson@ei.sigma.se
Operating system: Redhat 6.2
PHP version: 4.0.1
PHP Bug Type: LDAP related
Bug description: Unable to add binary data to LDAP
It is not possible to add binary data using ldap_add functions in PHP.
This is not the same as bug #5702, where John Hallam tries to fill the jpegphoto attribute with a
base64 encoded jpeg picture, i.e. non-binary (an approach I think is not correct by the way, since
the LDAP server wants binary data in binary form).
Try the following script:
<?php
$userfile = "./test.jpg";
$fd = fopen ($userfile, "r");
$fsize = filesize ($userfile);
echo "FILE_LEN: ".$fsize;
$jpegStr = fread ($fd, $fsize);
fclose ($fd);
echo " STR_LEN: ".strlen($jpegStr);
echo " DATA: $jpegStr";
$ldapServerAddress = "ldap";
$ldapLoginName = "cn=admin,dc=se";
$ldapLoginPassword = "secret";
$ldapConn = ldap_connect($ldapServerAddress);
ldap_bind($ldapConn,
$ldapLoginName,
$ldapLoginPassword);
ldap_add($ldapConn,
"cn=person,dc=se",
array("objectclass" => "inetorgperson",
"sn" => "surname",
"cn" => "common name",
"jpegphoto" => $jpegStr ) );
?>
Look at the result in e.g. Netscape's addressbook. It will only be a couple of bytes in length.
/Johan