PHP 4.0 Bug #5702: Inserting an uploaded JPEG file into Openldap
| From: | john dot hallam at compaq dot com | Date: | Thu, 20 Jul 2000 14:48:53 +0000 |
| Subject: | PHP 4.0 Bug #5702: Inserting an uploaded JPEG file into Openldap | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-25227@lists.php.net to get a copy of this message | ||
From: john.hallam@compaq.com
Operating system: SuSE Linux 6.3
PHP version: 4.0.1pl2
PHP Bug Type: LDAP related
Bug description: Inserting an uploaded JPEG file into Openldap
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)