Edit report at https://bugs.php.net/bug.php?id=2507&edit=1
ID: 2507
Comment by: dhiraj dot w87 at gmail dot com
Reported by: jmi at softway dot fr
Summary: jpegphoto & LDAP problem
Status: Closed
Type: Bug
Package: LDAP related
Operating System: Linux
PHP Version: 3.0.12
Assigned To: venaas
Block user comment: N
Private report: N
New Comment:
try with this code its work for me
$image="images.jpg";
echo "----image-----",$image;
$data = fopen ($image, 'rb');
$size=filesize ($image);
echo "----size----",$size;
$contents= fread ($data, $size);
fclose ($data);
$encoded= base64_encode($contents);
echo $encoded;
$jpegStr=base64_decode($encoded);
$ldaprecord['jpegPhoto'] = $jpegStr;
Previous Comments:
------------------------------------------------------------------------
[1999-10-13 14:20:47] venaas at cvs dot php dot net
The LDAP functions in 3.0.12 do not work with binary data. The next
release will have a function ldap_get_values_len() that you can use. The
reason for this is that the C API has separate functions for string and
binary data, and the present functions use the string functions. For
more info on the C API you might look at for instance
http://developer.netscape.com/docs/manuals/dirsdk/csdk30/
ldap_get_values_len() is used just like ldap_get_values(). Here's some
code:
$sr=ldap_read($ds, $dn, "objectClass=*", array( "jpegphoto" ));
$ei=ldap_first_entry($ds, $sr);
$data = ldap_get_values_len($ds, $ei, "jpegphoto");
header("Content-type: image/jpeg");
echo $info[0];
There might be a while until the next release, you can get the current
CVS version, http://cvs.php.net/ explains how.
------------------------------------------------------------------------
[1999-10-13 12:32:55] jmi at softway dot fr
I use this little snippet of code to retreive a jpeg image from the directory.
--CODE--
$sr=ldap_read($ds,"$dnpic","jpegphoto=*",array("jpegphoto"));
$info = ldap_get_entries($ds, $sr);
Header("Content-type: image/jpeg");
echo $info[0]["jpegphoto"][0];
$f = fopen("/tmp/fil.jpg","w");
fwrite($f,$info[0]["jpegphoto"][0]);
--CODE--
The file /tmp/fil.jpg will contain all bytes in the image up til the first NULL byte occurence where
it is cut off.
Using ldap_search() with appropriate params yields the same result. And I have tested to retreive
the image using LDAP command-line clients - works fine.
The image data is stored in binary format (Netscape Directory model).
If I use this command (ldapsearch is from the openldap package):
ldapsearch -B -h monza -b "ou=people,o=softway,c=fr" "uid=jmi*" jpegphoto
I retrieve the beginning of the the jpeg picture until the first null byte occurence.
This is how it's seems to work with this php3 script.
However, if I add the -L option in this ldapsearch command, I can retrieve all the jpeg file in LDIF
format.
Is there a special option to retrieve the jpegphoto data in an other format like BASE64 ?
Thanks
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=2507&edit=1