Outputting an Image in PHP
In PHP, displaying an image in a web browser involves sending the image data along with appropriate headers. To achieve this, you can follow these steps:
1. Determine the Image File and MIME Type:
2. Send Content Headers:
3. Read and Output the Image Data:
Example:
$file = '../image.jpg'; $type = 'image/jpeg'; header('Content-Type:'.$type); header('Content-Length: ' . filesize($file)); readfile($file);
By using this code, you can output an image directly to the browser, allowing it to be displayed on the web page.
The above is the detailed content of How to Output an Image in PHP?. For more information, please follow other related articles on the PHP Chinese website!