check for image_path exists and set http status header

This commit is contained in:
2024-05-16 16:07:20 -05:00
parent 5361b0da90
commit 8c0b1e3c19

View File

@@ -184,6 +184,17 @@ add_action('template_redirect', 'handle_image_request');
function serve_image($image_path) {
header('Content-Type: image/png');
if (file_exists($image_path)) {
status_header( 200 );
} else {
status_header( 404 );
die("Image not found.");
}
// Clear all output buffering to prevent any extra output
while (ob_get_level()) {
ob_end_clean();
}
readfile($image_path);
}