How to save an image from url using PHP? -


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 receive warning:

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

i try save image curl not work too.

the php code seems technically correct seems 1 reason or blocked. assuming trying browser on same machine , works, guess on useragent string filtering. try using valid user agent string curl.

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

-a, --user-agent

(http) specify user-agent string send http server. badly done cgis fail if field isn't set "mozilla/4.0". encode blanks in string, surround string single quote marks. can set -h, --header option of course.

if option set more once, last 1 one that's used.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -