isFileInStore($file)) { // Try the PDF store $pdf_store = new \classes\pdf_store(); if ($pdf_store->isFileInStore(str_replace('/files/', '', $file))) { // Download the certificate from the PDF store to /tmp $certificate_path = $pdf_store->download(str_replace('/files/', '', $file)); // Send the certificate to the client header('Content-Type: application/pdf'); header('Content-Disposition: inline; filename="' . str_replace('/files/', '', $file) . '"'); header('Content-Length: ' . filesize($certificate_path)); readfile($certificate_path); // Delete the certificate from /tmp after sending it unlink($certificate_path); exit; } echo 'Certificate not found in store' . $file; //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); // Delete the certificate from /tmp after sending it unlink($certificate_path); exit; } // If the file is an attachment, serve it as a download if ($isAttachment) { $attachment_store = new \classes\attachment_store(); $file = str_replace('/files/', '', $file); // Check if the file exists in the attachment store if (!$attachment_store->isFileInStore($file)) { echo 'Attachment '. $file .' not found in store'; exit; } // Download the file from the store to /tmp $file_path = $attachment_store->download($file); // Send the file to the client if ($isPreview) { header('Content-Type: ' . mime_content_type($file_path)); header('Content-Disposition: inline; filename="' . basename($file_path) . '"'); } else { header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . basename($file_path) . '"'); } header('Content-Length: ' . filesize($file_path)); readfile($file_path); // Delete the file from /tmp after sending it unlink($file_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); // Delete the file from /tmp after sending it unlink($file_path); exit; }