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.
This commit is contained in:
@@ -1,24 +1,51 @@
|
||||
<?php
|
||||
// Get the file name from the URL
|
||||
$file = $_SERVER['REQUEST_URI'];
|
||||
$file = str_replace('/modules/washcertificates/output/certificates/', '', $file);
|
||||
$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();
|
||||
$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');
|
||||
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;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
Reference in New Issue
Block a user