How can PHP headers be utilized to output an image as a response to an HTML img tag?
To output an image as a response to an HTML img tag using PHP headers, you can set the content-type header to "image/jpeg" (or the appropriate image type) and then use readfile() to output the image file. This will allow the image to be displayed in the HTML img tag.
<?php
// Set the content type header to image/jpeg
header('Content-Type: image/jpeg');
// Output the image file using readfile
readfile('path/to/image.jpg');
?>
Related Questions
- How can the "Parse error" issue be resolved when accessing a field named "24_Hours" in PHP?
- How can one troubleshoot and resolve the error message "supplied argument is not a valid MySQL result resource" in PHP?
- How can one ensure that error messages are displayed on the same page after form submission in PHP?