$img=file_get_contents('http://example.com/image/test.jpg'); file_put_contents('/your/project/folder/imgname.jpg',$img);
This works only if allow_url_fopen is set to 1 in your php.ini file. If you can change this value, enable it and you're done.
Another option is CURL. Check if this module is enabled in your PHP configuration.
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://example.com/image/test.jpg'); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_HEADER , 0); curl_setopt($ch, CURLOPT_VERBOSE, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $result = @curl_exec($ch); $curl_err = curl_error($ch); curl_close($ch); if (empty($curl_err)) { file_put_contents('/your/project/folder/imgname.jpg',$result); }
If CURL is not enabled, your chance is to write a simple HTTP client like this:
$buf=''; $fp = fsockopen('example.com',80); fputs($fp, "GET /image/test.jpg HTTP/1.1\n" ); fputs($fp, "Host: example.com\n" ); fputs($fp, "Connection: close\n\n" ); while (!feof($fp)) { $buf .= fgets($fp,128); } fclose($fp); file_put_contents('/your/project/folder/imgname.jpg',$buf);
file_get_contents()won't. If you gave us the full URL it would be way simpler, we cannot just guess what's the real problem here.