Commit 0c7320d6 authored by Carsten  Rose's avatar Carsten Rose
Browse files

B6331 / File Upload: Wrong error message if filesize is much too big.

parent 62a8f97c
......@@ -241,6 +241,7 @@ const ERROR_UPLOAD_FILE_TYPE = 1502;
const ERROR_UPLOAD_GET_MIME_TYPE = 1503;
const ERROR_UPLOAD_UNKNOWN_ACTION = 1504;
const ERROR_NO_TARGET_PATH_FILE_NAME = 1505;
const ERROR_UPLOAD_FILES_BROKEN = 1506;
// LDAP / typeahead
const ERROR_LDAP_CONNECT = 1600;
......
......@@ -60,6 +60,14 @@ class File {
$sipUpload = $this->store->getVar(SIP_SIP, STORE_SIP);
if ($sipUpload === false) {
// Throws an exception if content is too big - if content is bigger than 'post_max_size', the POST is lost together with the PHP Upload error message.
$this->checkMaxFileSize($_SERVER['CONTENT_LENGTH']);
if(empty($_FILES)){
throw new UserFormException('Missing $_FILES[] - the whole request seems broken', ERROR_UPLOAD_FILES_BROKEN);
}
throw new UserFormException('SIP invalid: ' . $sipUpload, ERROR_SIP_INVALID);
}
$statusUpload = $this->store->getVar($sipUpload, STORE_EXTRA, SANITIZE_ALLOW_ALL);
......@@ -80,6 +88,24 @@ class File {
}
}
/**
* @param $size
* @throws CodeException
* @throws UserFormException
*/
private function checkMaxFileSize($size) {
$maxFileSize = $this->store->getVar(FE_FILE_MAX_FILE_SIZE, STORE_SIP);
$msg = 'File too big.';
if($maxFileSize!==false){
$msg .= ' Max allowed size: ' . $maxFileSize;
}
if ($size >= $maxFileSize) {
throw new UserFormException($msg, ERROR_UPLOAD_TOO_BIG);
}
}
/**
* @param string $sipUpload
* @param array $statusUpload
......@@ -96,10 +122,7 @@ class File {
throw new UserFormException($this->uploadErrMsg[$newArr[FILES_ERROR]], ERROR_UPLOAD);
}
$maxFileSize = $this->store->getVar(FE_FILE_MAX_FILE_SIZE, STORE_SIP);
if ($statusUpload['size'] >= $maxFileSize) {
throw new UserFormException('File to big. Max size allowed: ' . $maxFileSize, ERROR_UPLOAD_TOO_BIG);
}
$this->checkMaxFileSize($statusUpload['size']);
$accept = $this->store->getVar(FE_FILE_MIME_TYPE_ACCEPT, STORE_SIP);
if (!$this->checkFileType($statusUpload['tmp_name'], $statusUpload['name'], $accept)) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment