php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #5702 Inserting an uploaded JPEG file into Openldap
Submitted: 2000-07-20 16:48 UTC Modified: 2000-07-29 00:48 UTC
From: john dot hallam at compaq dot com Assigned:
Status: Closed Package: LDAP related
PHP Version: 4.0.1pl2 OS: SuSE Linux 6.3
Private report: No CVE-ID: None
 [2000-07-20 16:48 UTC] john dot hallam at compaq dot com
I'm having trouble inserting a JPEG file into the jpegphoto attribute (Openldap 1.2.11).

From the documentation I have read I should be storing a base64 value in the jpegphoto attribute. I have managed to insert the photo with an ldap client and then made an LDIF extract to look at the base64 encoding. When I try to insert the jpegphoto with PHP, the base64 encoding is identical (I did an "echo" to print things on the screen) as to what I see with the LDIF extract. When I look at the openldap database I see totally different values than what I expect.

When I insert the jpegphoto with an LDAP client (LDAP Browser/Editor by Jarek Gawor - freeware) I can display the photo with the Netscape browser and I can see the base64 encoding correctly on the slapd server.

Here is the php code excerpt that shows you what I am doing :-

// Get the JPEG file. $AttributeValue is the JPEG file to upload

if ($Str_or_Bin == "binary") {
	if (!$file=fopen($AttributeValue, "r")) {
		print "<h3>Error: Upload of binary file failed</h3>";
		exit;
	}
else {
	$AttributeValue = chunk_split(base64_encode(fread($file,"$AttributeValue_size")));
	fclose($file);
	}
}
.
.
.
.
// Insert JPEG file into LDAP database
// $AttributeValue contains the base64 encoding
// $AttributeName is jpegphoto
<?php
$info[$AttributeName] = $AttributeValue;
// Example of the echo printout after this code
echo "AND KNOW IT IS ".$info[$AttributeName]."<br><br><br>";
@$ds=ldap_connect($Host);
if ($ds) {
	@$r=ldap_bind($ds, $AdminDN, $Password);
	if ($r) {
		@$result = ldap_mod_add($ds, $PersonDN, $info);
		if ($result) {
			print '<h3>Addition Successful</h3>';
.
.
Here is what the 'echo "AND KNOW IT IS ".$info[$AttributeName]."<br><br><br>";' gives me

AND KNOW IT IS /9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAwICQoJBwwKCgoNDQwOEh4TEhAQEiQaGxUeKyYtLCom
KSkvNUQ6LzJAMykpO1E8QEZJTE1MLjlUWlNKWURLTEn/2wBDAQ0NDRIQEiMTEyNJMSkxSUlJSUlJ
SUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUn/wAARCAH0AXcDASIA
AhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA
AAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3
.
.
.
f+poooQDQoY8+hoI+Zvx5/OiimA3HzUoP8qKKAQjHjdgZNRk4XjiiigQgPT60buM4HFFFABn5qlI
5xzRRSew1uN3GnKxJOcevSiilEOoucZ9hn9aVeU5J4Jx+n+NFFMAT5mA/vcH8qFOSM+tFFMB3Rd3
f/P+FIScg/7JP8/8KKKAEf8A1hH1FOx85X37/XH9aKKXQBNxAznPzYp3oOzdfyoooGOAznt0PH50
0jGD7f0oooQCkct/n1/wpzoBzkk+/wBKKKQEX8J+ooooplI//9k= 

Is there a bug or am I doing something wrong ??

I've spent days trying to get it right/searching for an answer and I even upgraded from php3.0.14/openldap-1.2.10 so I'd be very grateful for any input.

Thanks & Regards
John, Compaq in Switzerland

PS php.ini has not been modified (eg. it's the same as php.ini-dist supplied with the php-4.0.1pl2) 




Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-07-24 16:30 UTC] sniper@php.net
Closed. See bug #5759 for reason.

--Jani
 [2000-07-29 00:48 UTC] sniper@php.net
Fixed in CVS. There is no need to base64_encode() that 
jpeg-file. Just read it into a variable as it is.

Please check bug #5759 for an example code.

--Jani
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Oct 30 22:01:28 2024 UTC