Take the 2-minute tour ×

I have php application that serve image, the image is coming from a remote URL and passing it to the browser with content type image. My code has 2 steps:

  1. Using curl to check the http header response. If it is a valid image (httpcode 200).
  2. if httpcode is 200, I used readfile function with header content-type: image/jpg.

For me the approach above is not a good idea because it makes 2 http hit. My goal is to make the 2 steps above just one using CURL. Is it possible?

Appreciate any inputs on this.


share|improve this question
How about using readfile without verifying, and handling the error for readfile? –  xFortyFourx Feb 23 '13 at 6:03
Why do you care? –  Toby Allen Feb 23 '13 at 7:43
Can you not just use an img tag and refernce the image directly in the page? –  Toby Allen Feb 23 '13 at 7:43
I need to verify if the image exist because 1 requirement is to give the alternative image if the first image do not exist. Using readfile it self doesn't give me information about the http header. I forgot to mentioned that I am also getting the last-modified, etag and the file size of the remote URL and passing it to the browser –  user2101565 Feb 23 '13 at 7:46
It needs to be content-type: image/jpg, because clients are downloading the image. –  user2101565 Feb 23 '13 at 7:52
show 1 more comment


Your Answer



Browse other questions tagged or ask your own question.