|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #2507 jpegphoto & LDAP problem
Submitted: 1999-10-13 12:32 UTC Modified: 1999-10-13 14:20 UTC
From: jmi at softway dot fr Assigned: venaas (profile)
Status: Closed Package: LDAP related
PHP Version: 3.0.12 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: jmi at softway dot fr
New email:
PHP Version: OS:


 [1999-10-13 12:32 UTC] jmi at softway dot fr
I use this little snippet of code to retreive a jpeg image from the directory.

$info = ldap_get_entries($ds, $sr);
Header("Content-type: image/jpeg");
echo $info[0]["jpegphoto"][0];
$f = fopen("/tmp/fil.jpg","w");


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 ?



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [1999-10-13 14:20 UTC] 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

ldap_get_values_len()  is used just like ldap_get_values(). Here's some

$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, explains how.
 [2013-04-10 06:26 UTC] dhiraj dot w87 at gmail dot com
try with this code its work for me
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;
$ldaprecord['jpegPhoto'] = $jpegStr;
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 24 02:01:32 2024 UTC