Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I directly display an image using PHP?

Tags:

php

image

I have a question about displaying images in PHP. I need to have a PHP file display as JUST an image, as opposed to an image embedded in a web page, as if you had browsed to the JPEG image directly. The reason that I need it to be a PHP page as opposed to actually browsing to the image is that I need to resize the image before it is delivered. It would be easiest to use an image directly because that way I can display the image in a desktop application more easily. Is there any way to do this? Thanks!

like image 746
Michael Cheal Avatar asked Jan 24 '13 14:01

Michael Cheal


1 Answers

<?php
header('Content-Type: image/jpeg');
readfile('path/to/image.jpeg');
like image 52
Cobra_Fast Avatar answered Sep 30 '22 14:09

Cobra_Fast