1

Is there a way to display external images with PHP having cache?

I want display images like: www.domain.com/safe_image.php?url=external.site.jpg

Basically like what Facebook does.

What's best way to achieve this?

Thanks.

Edit

This is my code now:

$image_url = $_GET['url']; 

$ch = curl_init(); 
$timeout = 0; 
curl_setopt ($ch, CURLOPT_URL, $image_url); 
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 

// Getting binary data 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); 

$image = curl_exec($ch); 
curl_close($ch); 

// output to browser 
header("Content-type: image/jpeg"); 
print $image; 
PGZ
  • 485
  • 1
  • 5
  • 11
  • Well, cache them locally. What exactly is your question? How to fetch the image? How to implement the caching? – Pekka Oct 23 '10 at 13:05
  • My question is how to cache it? I edited the post with my actual code. – PGZ Oct 23 '10 at 13:11

1 Answers1

1

Check my answer at Images caching in browser - app-engine-patch aplication it is for python but I am sure that you will get the idea

Community
  • 1
  • 1
Ilian Iliev
  • 3,217
  • 4
  • 26
  • 51
  • 1
    He's talking about external links to images here, not images stored locally. Your post refers to images stored in the GAE Datastore. – Jude Osborn Feb 07 '13 at 22:42