-
Notifications
You must be signed in to change notification settings - Fork 4
/
image.php
executable file
·59 lines (48 loc) · 1.29 KB
/
image.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
55
56
57
58
59
<?php
/*
* This file is intended to serve the right image.
*
*
*/
// Set the content type header - in this case image/png
header('Content-Type: image/png');
require('rooms.php');
require('theme_settings.php');
if (isset($_GET["g"])) {
$image = __DIR__ . "/images/" . strtolower($_GET["g"]) . ".png";
} else if (isset($_GET["b"])) {
$image = __DIR__ . "/images/" . strtolower($_GET["b"]) . ".png";
} else {
$i = NULL;
//grab url information
//should be hostname of RPi via puppet or any other URI
foreach ($rooms as $r) {
foreach ($r['rpi'] as $h) {
if (strtolower($_GET["i"]) == strtolower($h)) {
$i = TRUE;
break;
}
}
//end the foreach when hostname/rpi is found
if (!is_null($i)) { $image = __DIR__ . "/images/" . strtolower($r['name']) . ".png"; break; }
}
}
//find right image in directory
if (file_exists($image)) {
// open the file in a binary mode
$fp = fopen($image, 'rb');
// send the right headers
header("Content-Length: " . filesize($image));
// dump the picture and stop the script
fpassthru($fp);
exit;
} else {
//return not found image
$f = __DIR__ . "/theme/{$theme}/images/none.jpg";
$fp = fopen($f, 'rb');
// send the right headers
header("Content-Length: " . filesize($f));
// dump the picture and stop the script
fpassthru($fp);
exit;
}