require_once('../../../wp-load.php'); if (isset($_GET['pdf'])) { $pdf_url = urldecode($_GET['pdf']); $pdf_path = str_replace(home_url(), ABSPATH, $pdf_url); // Check if the file exists and is readable if (file_exists($pdf_path) && is_readable($pdf_path)) { // Get the file extension $extension = strtolower(pathinfo($pdf_path, PATHINFO_EXTENSION)); // Set the appropriate content type based on the file extension $content_type = ''; switch ($extension) { case 'pdf': $content_type = 'application/pdf'; break; case 'doc': $content_type = 'application/msword'; break; case 'docx': $content_type = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; break; case 'xls': $content_type = 'application/'; break; case 'xlsx': $content_type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; break; default: // Set a generic content type for unsupported file types $content_type = 'application/octet-stream'; } // Set the appropriate headers for the file display header("Content-Type: $content_type"); readfile($pdf_path); exit; } } // If the file is not found or is not readable, handle the 404 error global $wp_query; $wp_query->set_404(); status_header(404); get_template_part(404); exit();