php.net |  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
 [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.

--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





Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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
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.
 [2013-04-10 06:26 UTC] dhiraj dot w87 at gmail dot com
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;
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 17:01:31 2024 UTC