add FileUploadException
This commit is contained in:
parent
8abf29b2b0
commit
1a11d220a9
3 changed files with 91 additions and 3 deletions
|
|
@ -49,6 +49,13 @@
|
|||
{
|
||||
$answer = $_FILES['answers'];
|
||||
|
||||
// Check error
|
||||
if($answer['error'] !== 0) {
|
||||
throw new \hhu\z\exceptions\SubmissionNotValidException(
|
||||
new \hhu\z\exceptions\FileUploadException($answer['error'])
|
||||
);
|
||||
}
|
||||
|
||||
// Check mimetype
|
||||
$mimetypes = $this->Submit->getAllowedMimetypes($seminary['id']);
|
||||
$answerMimetype = null;
|
||||
|
|
@ -58,13 +65,13 @@
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Check file
|
||||
if(is_null($answerMimetype)) {
|
||||
throw new \hhu\z\exceptions\SubmissionNotValidException(
|
||||
new \hhu\z\exceptions\WrongFiletypeException()
|
||||
);
|
||||
}
|
||||
|
||||
// Check file size
|
||||
if($answer['size'] > $answerMimetype['size']) {
|
||||
throw new \hhu\z\exceptions\SubmissionNotValidException(
|
||||
new \hhu\z\exceptions\MaxFilesizeException()
|
||||
|
|
@ -72,7 +79,11 @@
|
|||
}
|
||||
|
||||
// Save file
|
||||
$this->Submit->setCharacterSubmission($seminary['id'], $quest['id'], $this->Auth->getUserId(), $character['id'], $answer);
|
||||
if(!$this->Submit->setCharacterSubmission($seminary['id'], $quest['id'], $this->Auth->getUserId(), $character['id'], $answer)) {
|
||||
throw new \hhu\z\exceptions\SubmissionNotValidException(
|
||||
new \hhu\z\exceptions\FileUploadException(error_get_last()['message'])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
<?=_('File has wrong type')?>
|
||||
<?php elseif($exception->getNestedException() instanceof \hhu\z\exceptions\WrongFiletypeException) : ?>
|
||||
<?=_('File exceeds size maximum')?>
|
||||
<?php elseif($exception->getNestedException() instanceof \hhu\z\exceptions\FileUploadException) : ?>
|
||||
<?=sprintf(_('Error during file upload: %s'), $exception->getNestedException()->getNestedMessage())?>
|
||||
<?php else : ?>
|
||||
<?=$exception->getNestedException()->getMessage()?>
|
||||
<?php endif ?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue