tags:

views:

75

answers:

2

Hi all,

I'm completly newbie to PHP. i want a code to load a image to PHP server and then send it to browser. for example i want to once page named sample.php is requested, in response send an image to browser... in other words, I want to create a PHP file that acts like a proxy...

Thanks all

A: 

You need to use
$image = fopen("image.png");
Modify the headers(not sure exacly if it's correct) headers("Content-type: image/png");
And then send the image
echo fread($image, file_size("image.png"));

Dani
A: 

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

header("Location: address-of-image");

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

readfile("http://www.example.com/image.jpg")

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

header("Content-type: application/octet-stream")

one more thing to consider may be setting correct headers for caching...

Joe Hopfgartner