I want code that loads an image to a PHP server and then send it to browser.
For example I want
sample.php to send an image to browser once it is requested. in other words, I want to create a PHP file that acts like a proxy for an image.
why are you doing this? why don't deliver the image directly? if you are trying to display a random image you may as well just redirect to the image using
for delivering the file to your clients from your server and not from its original location you can just do. however your php.ini settings need to allow external file opens
correct headers are not required if you are going to display the image in an img tag, altough i would recommend it. you should check the filetype of the image or in most cases just set an octet-stream header so the browser doesnt assume an incorrect type like text or something and tries to display binary data. to do so just do
one more thing to consider may be setting correct headers for caching...
You need to use
$image = fopen("image.png");
Modify the headers(not sure exacly if it's correct)
And then send the image
echo fread($image, file_size("image.png"));