From b2a7cfb9b152dcad1333b92dde76af3a164af8f6 Mon Sep 17 00:00:00 2001 From: jesse Date: Fri, 27 May 2011 11:57:02 -0700 Subject: Got image posting finished. --- htdocs/postimages.php | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 htdocs/postimages.php (limited to 'htdocs/postimages.php') diff --git a/htdocs/postimages.php b/htdocs/postimages.php new file mode 100644 index 0000000..375e8d7 --- /dev/null +++ b/htdocs/postimages.php @@ -0,0 +1,55 @@ + + * + */ + +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; +} + +?> + -- cgit v1.2.3