-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.php
More file actions
38 lines (38 loc) · 1.17 KB
/
proxy.php
File metadata and controls
38 lines (38 loc) · 1.17 KB
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
<?php
// define absolute path to image folder
$image_folder = '/home/mydomain/upload_folder/';
// get the image name from the query string
// and make sure it's not trying to probe your file system
if (isset($_GET['pic']) && basename($_GET['pic']) == $_GET['pic']) {
$pic = $image_folder.$_GET['pic'];
if (file_exists($pic) && is_readable($pic)) {
// get the filename extension
$ext = substr($pic, -3);
// set the MIME type
switch ($ext) {
case 'jpg':
$mime = 'image/jpeg';
break;
case 'gif':
$mime = 'image/gif';
break;
case 'png':
$mime = 'image/png';
break;
default:
$mime = false;
}
// if a valid MIME type exists, display the image
// by sending appropriate headers and streaming the file
if ($mime) {
header('Content-type: '.$mime);
header('Content-length: '.filesize($pic));
$file = @ fopen($pic, 'rb');
if ($file) {
fpassthru($file);
exit;
}
}
}
}
?>