Displaying Images in PHP
This question focuses on displaying an image in the browser using PHP. The problem involves accessing an image file, retrieving its MIME type, and then sending it as a response to the browser.
Solution:
The solution provided involves using the header() function to set the appropriate MIME type for the image, and the filesize() function to determine the size of the image file. The readfile() function is then used to read the contents of the image file and output it to the browser.
Here's a code snippet that demonstrates the solution:
$file = '../image.jpg'; $type = 'image/jpeg'; header('Content-Type:'.$type); header('Content-Length: ' . filesize($file)); readfile($file);
By following these steps, the image file will be successfully displayed in the browser.
The above is the detailed content of How Can I Display an Image in a Browser Using PHP?. For more information, please follow other related articles on the PHP Chinese website!