aboutsummaryrefslogtreecommitdiff
path: root/foto/protected.php
blob: c70772d182d480a76d043a0bcad9e8a02eee7ed6 (plain)
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
<?php

lredirect("index");

if ( ! isset($_GET["type"]) || ! isset($_GET["id"]) )
	exit;

switch($_GET["type"]){
	case("image"):
		$sql = $db->prepare("SELECT name, mime, size, hash FROM " . DBPREFIX . "image WHERE id = %s;", $_GET["id"]);
		$result = $db->doQuery($sql);
		$f = $result->fetch_array(MYSQLI_ASSOC);
		if ( ! file_exists(IMAGE_PATH . $f["hash"] . ".gz") ){
			header($_SERVER["HTTP_PROTOCOL"] . " 404 Not Found");
		} else {
			header("Content-Type: " . $f["mime"]);
			header("Content-Disposition: inline; filename=".$f["name"]);
			header("Content-Length: " . $f["size"]);

			readgzfile(IMAGE_PATH . $f["hash"] . ".gz");
		}
		break;
	default:
		header($_SERVER["HTTP_PROTOCOL"] . " 404 Not Found");
}