3

I created a script to load an image from an URL using CURL. To test that the file is a JPG, I'm using ($info['content_type'] == 'image/jpeg'). It works on most of the urls, but some return a html type : e.g http://www.super-fond.fr/IMAGES_VOITURES/lexus/2005-Lexus-LF-A-Concept-R-1280x960.jpg Could anyone tell me why this URL is html ?

Thanks

6
  • The only person who could tell you for sure is the owner of super-fond.fr, as this is a server configuration problem. I suspect Browsers looks at the extension as well to determine file type, which is why they can see it... Commented Jun 27, 2011 at 18:26
  • post the source code of your CURL steps Commented Jun 27, 2011 at 18:26
  • What is the content of the HTML? It might just say that hot-linking is not allowed on the image. Commented Jun 27, 2011 at 18:26
  • I don't know why, but if you receive a text/html, you can use imagecreatefromstring($string) to check if it's an image. Commented Jun 27, 2011 at 18:26
  • 1
    Actually, looking at that specific image, it appears to be sending the proper content type, so I'm not sure... Commented Jun 27, 2011 at 18:26

1 Answer 1

4

It is because you not set a user-agent in request headers and this host rejects request with specific user-agent.

See CURLOPT_USERAGENT in curl_setopt() on how to set the user-agent:

curl_setopt($c, CURLOPT_USERAGENT, 'Mozilla');
Sign up to request clarification or add additional context in comments.

1 Comment

That should solve it. Checked with CURL on commandline, -A Mozilla serves a 200 OK instead of 403 Forbidden.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.