Files
api/services/nginx/app/file_server.php
T
Jeppe Bundgaard a0fd41fba1 Add image upload support, file handling improvements, and OpenAI integration
- Introduced `uploadRoute` to handle image uploads with MIME type validation and size restrictions.
- Added `upload_store` class for managing file storage and generating presigned URLs for upload/download.
- Enhanced file server to differentiate between PDFs and uploaded files, supporting dynamic content delivery.
- Integrated OpenAI module for License Plate Recognition (LPR), including API configuration and schema validation.
- Updated core structure with new interfaces (`minio_uploads_i`, `openai_i`) and classes (`openai`, `upload_store`).
- Adjusted `index.php` and file routes to support dynamic MIME checks and direct link generation.
2025-08-18 16:50:30 +02:00

51 lines
1.7 KiB
PHP

<?php
// Get the file name from the URL
$file = $_SERVER['REQUEST_URI'];
$isPDF = false;
// Check if the filetype is .pdf
if (preg_match('/\.pdf$/', $file)) {
$isPDF = true;
}
if ($isPDF) {
$file = str_replace('/modules/washcertificates/output/certificates/', '', $file);
// Download the file from minio, and send it to the client
$wash_certificate_store = new \classes\wash_certificate_store();
// Check if the certificate exists
if (!$wash_certificate_store->isFileInStore($file)) {
echo 'Certificate not found in store';
//header('HTTP/1.1 404 Not Found');
exit;
}
// Download the certificate from the store to /tmp
$certificate_path = $wash_certificate_store->download($file);
// Send the certificate to the client
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="' . $file . '"');
header('Content-Length: ' . filesize($certificate_path));
readfile($certificate_path);
exit;
}
// Check if the file might be a temporary static file
if (!$isPDF) {
$uploads = new \classes\upload_store();
$file = str_replace('/files/', '', $file);
// Check if the file exists in the upload store
if (!$uploads->isFileInStore($file)) {
echo 'File not found in store';
exit;
}
// Download the file from the store to /tmp
$file_path = $uploads->download($file);
// Send the file to the client
$mime_type = mime_content_type($file_path);
header('Content-Type: ' . $mime_type);
header('Content-Disposition: inline; filename="' . basename($file_path) . '"');
header('Content-Length: ' . filesize($file_path));
readfile($file_path);
exit;
}