Uploading: empty files yield better error message
This commit is contained in:
parent
81017e18cb
commit
18f7fff21f
1 changed files with 6 additions and 2 deletions
|
@ -238,6 +238,12 @@ class Model_Post extends AbstractModel
|
||||||
|
|
||||||
public function setContentFromPath($srcPath)
|
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);
|
$this->mime_type = mime_content_type($srcPath);
|
||||||
switch ($this->mime_type)
|
switch ($this->mime_type)
|
||||||
{
|
{
|
||||||
|
@ -260,8 +266,6 @@ class Model_Post extends AbstractModel
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->orig_name = basename($srcPath);
|
$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]);
|
$duplicatedPost = R::findOne('post', 'file_hash = ?', [$this->file_hash]);
|
||||||
if ($duplicatedPost !== null)
|
if ($duplicatedPost !== null)
|
||||||
throw new SimpleException('Duplicate upload: @' . $duplicatedPost->id);
|
throw new SimpleException('Duplicate upload: @' . $duplicatedPost->id);
|
||||||
|
|
Loading…
Reference in a new issue