-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetphoto.php
54 lines (45 loc) · 1.3 KB
/
getphoto.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
include "config.inc";
include "functions.inc";
function do_jpegphoto(&$photo) {
$tag = sprintf("\"%08x\"", crc32($photo));
// check if client has the ETag
if (isset($_SERVER['HTTP_IF_NONE_MATCH'])
and $tag == $_SERVER['HTTP_IF_NONE_MATCH']) {
header("{$_SERVER["SERVER_PROTOCOL"]} 304");
header("Status: 304");
header("Content-Length: 0");
}
else {
header("ETag: {$tag}");
header("Content-Type: image/jpeg");
header("Content-Length: ".strlen($photo));
print $photo;
}
}
$conn = ldap_connect_and_do_things();
if (!$conn) {
header("Content-Type: text/plain");
print_r($SysErrors);
die();
}
$uid = $_GET["uid"];
$search = @ldap_read($conn, "uid={$uid},ou=people,dc=cluenet,dc=org",
"(objectClass=*)", array("jpegphoto", "modifyTimestamp"), false, 0);
if (!$search) {
// user entry for $uid not found
die("User not found\n");
}
$entry = ldap_first_entry($conn, $search);
// time the LDAP entry was modified
// no per-attribute mod times, but close enough
$modtime = ldap_get_values($conn, $entry, "modifyTimestamp");
$modtime = ldif_parse_time($modtime[0]);
header("Last-Modified: ".date(DateTime::RFC2822, $modtime));
$photo = ldap_get_values_len($conn, $entry, "jpegphoto");
if ($photo !== false) {
ldap_unbind($conn);
do_jpegphoto($photo[0]);
} else {
header("Status: 404", true, 404);
}