Allow contacts to upload attachments when adding ticket replies in portal

- Adds the ability for contacts to add file attachments when posting a ticket reply
- Enhancements to checkFileUpload(): Adjust file reference name generation & bad extension handling
This commit is contained in:
Marcus Hill
2023-10-21 15:24:15 +01:00
parent 7aadad3597
commit 218cdcdc4c
3 changed files with 52 additions and 6 deletions

View File

@@ -628,12 +628,14 @@ function checkFileUpload($file, $allowed_extensions) {
// Check a file is actually attached/uploaded
if ($tmp === '') {
return "No file was uploaded.";
// No file uploaded
return false;
}
// Check the extension is allowed
if (!in_array($extension, $allowed_extensions)) {
return "File extension not allowed.";
// Extension not allowed
return false;
}
// Check the size is under 500 MB
@@ -649,7 +651,7 @@ function checkFileUpload($file, $allowed_extensions) {
$hashedContent = hash('sha256', $fileContent);
// Generate a secure filename using the hashed content
$secureFilename = $hashedContent . '.' . $extension;
$secureFilename = $hashedContent . randomString(2) . '.' . $extension;
return $secureFilename;
}