From 18f7fff21fa66c2e6d27a95bab45cce79a97c276 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sat, 23 Nov 2013 10:39:56 +0100 Subject: [PATCH] Uploading: empty files yield better error message --- src/Models/Model_Post.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Models/Model_Post.php b/src/Models/Model_Post.php index 22229554..c941147b 100644 --- a/src/Models/Model_Post.php +++ b/src/Models/Model_Post.php @@ -238,6 +238,12 @@ class Model_Post extends AbstractModel public function setContentFromPath($srcPath) { + $this->file_size = filesize($srcPath); + $this->file_hash = md5_file($srcPath); + + if ($this->file_size == 0) + throw new SimpleException('Specified file is empty'); + $this->mime_type = mime_content_type($srcPath); switch ($this->mime_type) { @@ -260,8 +266,6 @@ class Model_Post extends AbstractModel } $this->orig_name = basename($srcPath); - $this->file_size = filesize($srcPath); - $this->file_hash = md5_file($srcPath); $duplicatedPost = R::findOne('post', 'file_hash = ?', [$this->file_hash]); if ($duplicatedPost !== null) throw new SimpleException('Duplicate upload: @' . $duplicatedPost->id);