0

The image URL is: http://phim.xixam.com/thumb/giotdang.jpeg

My code is:

$img = 'http://phim.xixam.com/thumb/giotdang.jpeg';
file_puts_content('abc.jpg', file_get_contents($img));

But I receive Warning:

file_get_contents(http://phim.xixam.com/thumb/giotdang.jpeg) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in ...

I try save this image by cURL but not work too.

Hamza Zafeer
  • 2,360
  • 13
  • 30
  • 42
user895921
  • 49
  • 5

1 Answers1

0

The php code seems to be technically correct but it seems that for one reason or another you are blocked. Assuming you are trying it from the browser on the same machine and it works, I would guess on an UserAgent string filtering. Try Using a valid user agent string with cURL.

From http://curl.haxx.se/docs/manpage.html:

-A, --user-agent

(HTTP) Specify the User-Agent string to send to the HTTP server. Some badly done CGIs fail if this field isn't set to "Mozilla/4.0". To encode blanks in the string, surround the string with single quote marks. This can also be set with the -H, --header option of course.

If this option is set more than once, the last one will be the one that's used.

KillerX
  • 1,436
  • 1
  • 15
  • 23
  • I will try! This image url can show in browser. I use curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); but not work. :( – user895921 Jun 05 '12 at 01:35