Friday, November 5, 2010

Image retrieval with PHP

I developed a Flickr.com related project for an STB. The clients display the "Interesting Photos", allow search and full screen viewing, etc. The server-side coding is done with the PHP. Due to security issues the STB doesn't allow direct access to the outside world. As I didn't want to first download and then serve the images, I needed a method to serve the JPEG images directly. I found the small img.php file listed below works flawlessly:


The key point is not inserting anything outside the PHP block: let the file starts with the "<?php" and ends with the "?>".

Then, the STB clients simply prefix the requested image URL's with "img.php?url=" like this:

img.php?url=http://farm4.static.flickr.com/3587/3617423550_c6c6923569.jpg

Enjoy...

No comments: