From 7af236e2dea03ae3086f4d21e0ae1039c7ac3555 Mon Sep 17 00:00:00 2001 From: jesse Date: Thu, 26 May 2011 14:52:42 -0700 Subject: Working on image upload --- htdocs/new-post.php | 10 +++++++++- htdocs/src/Post.inc.php | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/htdocs/new-post.php b/htdocs/new-post.php index ea7c0b2..b4dd6ad 100644 --- a/htdocs/new-post.php +++ b/htdocs/new-post.php @@ -12,6 +12,8 @@ require_once "src/base.inc.php"; require_once "src/header.inc.php"; +const MAX_IMAGE_UPLOADS = 4; + echo "

New Posting

"; /* @@ -175,7 +177,7 @@ function handle_images() { form_start('finish'); - for ($i = 1; $i <= 4; $i++) { + for ($i = 1; $i <= MAX_IMAGE_UPLOADS; $i++) { echo "

"; } @@ -186,6 +188,12 @@ function handle_images() { function finish_images() { $post = $_SESSION['newpost']; + if (isset($_FILES['images']) and is_array($_FILES['images'])) { + foreach ($_FILES['images'] as $file) { + $post->addImage($file['tmp_name']); + } + } + return true; } diff --git a/htdocs/src/Post.inc.php b/htdocs/src/Post.inc.php index 6dec593..34230b2 100644 --- a/htdocs/src/Post.inc.php +++ b/htdocs/src/Post.inc.php @@ -186,6 +186,20 @@ class Post { return $this->info['location']; } + public function addImage($file) { + // TODO: Verify file type + + // TODO: Unique name for file. + $newfile = $GLOBALS['CONFIG']['uploads']; + + if (move_uploaded_file($file, $newfile)) { + return true; + + } else { + return false; + } + } + public function sendValidation() { $email = new Email($this->getEmail()); -- cgit v1.2.3