Uploading: empty files yield better error message

This commit is contained in:
Marcin Kurczewski 2013-11-23 10:39:56 +01:00
parent 81017e18cb
commit 18f7fff21f

View file

@ -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);