-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient_area_image_provider.php
78 lines (61 loc) · 2.12 KB
/
client_area_image_provider.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
session_start();
//check user is logged in
if (!empty($_SESSION["user"])) {
$user = $_SESSION["user"];
} else {
//TODO handle this better
die();
}
$size = $_GET['size'];
$mode = $_GET['mode'];
$file = $_GET['file'];
$imageProvider = new imageProvider($size, $mode, $file, $user);
$imageProvider->printImage();
class imageProvider {
//absolute path on your system to the client_area_files directory
//TODO - it would be nice if this didn't have to be set in all the PHP files
private $clientAreaDirectory = "/var/www/vhosts/mms-oxford.com/jwp_client_area_files";
public function __construct($size, $mode, $file, $user) {
$this->user = $user;
$this->size = $size;
$this->mode = $mode;
$this->file = $file;
$this->type = null;
$this->imageType();
}
private function imageType() {
if ((strpos(strtolower($this->file), 'jpg') !== false) or (strpos(strtolower($this->file), 'jpeg') !== false)) {
$this->type = 'jpeg';
} else if (strpos(strtolower($this->file), 'png') !== false) {
$this->type = 'png';
}
}
private function fail() {
$im = imagecreatetruecolor(150, 30);
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
imagestring($im, 1, 5, 5, 'Error loading ' . $this->file, $tc);
header('Content-type: image/jpeg');
imagejpeg($im);
imagedestroy($im);
}
public function printImage() {
if ($this->type === null) {
$this->fail();
}
$fnc = 'imagecreatefrom' . $this->type;
$filePath = $this->clientAreaDirectory . DIRECTORY_SEPARATOR . $this->user . DIRECTORY_SEPARATOR .
$this->mode . DIRECTORY_SEPARATOR . $this->size . DIRECTORY_SEPARATOR . $this->file;
$im = @$fnc($filePath);
if (!$im) {
$this->fail();
}
header('Content-Type: image/' . $this->type);
$fnc2 = 'image' . $this->type;
$fnc2($im);
imagedestroy($im);
}
}
?>