-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage.php
62 lines (54 loc) · 1.57 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
60
61
62
<?php
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
require_once __DIR__ . "/required.php";
$base = $SETTINGS['file_upload_path'] . "/";
if (isset($_GET['i'])) {
$file = $_GET['i'];
$filepath = $base . $file;
if (!file_exists($filepath) || is_dir($filepath)) {
http_response_code(404);
die("404 File Not Found");
}
if (strpos(realpath($filepath), $SETTINGS['file_upload_path']) !== 0) {
http_response_code(404);
die("404 File Not Found");
}
} else {
http_response_code(404);
die("404 File Not Found");
}
if (filesize($filepath) > 11) {
$imagetype = exif_imagetype($filepath);
} else {
$imagetype = false;
}
switch ($imagetype) {
case IMAGETYPE_JPEG:
$mimetype = "image/jpeg";
break;
case IMAGETYPE_GIF:
$mimetype = "image/gif";
break;
case IMAGETYPE_PNG:
$mimetype = "image/png";
break;
case IMAGETYPE_WEBP:
$mimetype = "image/webp";
break;
default:
$mimetype = "application/octet-stream";
}
header("Content-Type: $mimetype");
header('Content-Length: ' . filesize($filepath));
header("X-Content-Type-Options: nosniff");
$seconds_to_cache = 60 * 60 * 12; // 12 hours
$ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT";
header("Expires: $ts");
header("Pragma: cache");
header("Cache-Control: max-age=$seconds_to_cache");
ob_end_flush();
readfile($filepath);