summaryrefslogtreecommitdiff
path: root/htdocs/postimages.php
blob: 375e8d77580a6d146a89ca51a592d470b157e351 (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
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
<?php

/* Foursquare Community Site
 * 
 * Copyright (C) 2011 Foursquare Church.
 * 
 * Developers: Jesse Morgan <jmorgan@foursquarestaff.com>
 *
 */

require_once "src/base.inc.php";

// Make sure we had a path info
if (!isset($_SERVER['PATH_INFO'])) {
    errorNotFound();
}

// Clean up the id in the path info.
$id = substr($_SERVER['PATH_INFO'], 1);

if (!is_numeric($id)) {
    errorNotFound();
}

// Get the post.
$post = Post::getByImage($id);

if (!$post or 
    (!isset($_SESSION['currentUser']) and $post->getStage() != 'approved')) {
    errorNotFound();
}

// Check if file exists.
$file = $CONFIG['uploads'] . "/$id";

if (!file_exists($file)) {
    echo $file;
    errorNotFound();
}

// Output the file
$info = getimagesize($file);
header('Content-Type: ' . $info['mime']);
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;

function errorNotFound() {
    header("HTTP/1.0 404 Not Found");
    exit;
}

?>