Add validation for required file parameters in file_server.php

- Added checks for missing file name and file extension.
- Improved error handling with descriptive messages for missing parameters.
This commit is contained in:
Jeppe Bundgaard
2025-11-11 15:39:03 +01:00
parent 5193038bea
commit 0b566ee725
+12 -2
View File
@@ -18,6 +18,16 @@ if (preg_match('/\.pdf$/', $file)) {
$isAttachment = true;
}
}
// Require a filename
if (empty($file)) {
echo 'No file specified';
exit;
}
// Require an extension
if (!preg_match('/\.[a-zA-Z0-9]+$/', $file)) {
echo 'No file extension specified';
exit;
}
// Check if the file is an attachment
if (str_contains($file, 'temp_file_')) {
$isAttachment = true;
@@ -25,10 +35,10 @@ if (str_contains($file, 'temp_file_')) {
if ($isPDF && $isPDFStore) {
$file = str_replace('/modules/washcertificates/output/certificates/', '', $file);
// Download the file from minio, and send it to the client
// Download the file from minio, and send it to the client
$wash_certificate_store = new \classes\wash_certificate_store();
// Check if the certificate exists
// Check if the certificate exists
if (!$wash_certificate_store->isFileInStore($file)) {
// Try the PDF store
$pdf_store = new \classes\pdf_store();