If you have allow_url_fopen
set to true
:
$url = 'http://example.com/image.php';
$img = '/my/folder/flower.gif';
file_put_contents($img, file_get_contents($url));
Else use cURL:
$ch = curl_init('http://example.com/image.php');
$fp = fopen('/my/folder/flower.gif', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
$_GET
variable containing the URL of the imagehttp://example.com/fetch-image.php?url=http://blabla.com/flower.jpg
. In the case of this example, you could just call$_GET['url']
in your PHP script, like so:$ch = curl_init($_GET['url']);
. – Mathias Bynens Nov 29 '09 at 13:04