What functions should be used in PHP to output an image?
To output an image in PHP, you can use the `header()` function to set the content type to `image/jpeg`, `image/png`, or `image/gif`, depending on the image format. Then, you can use the `readfile()` function to output the image file.
<?php
$image = 'path/to/image.jpg'; // path to your image file
header('Content-Type: image/jpeg'); // set content type to JPEG
readfile($image); // output the image file
?>
Related Questions
- When considering whether to rewrite an old PHP script, what factors should be taken into account to determine if it is more efficient to start from scratch or refactor the existing code?
- How can PHP developers optimize their code to quickly check for existing usernames during registration processes?
- What are the potential security risks of allowing users to resubmit data in PHP applications?