1

Possible Duplicate:
PHP save image file

$image_url = 'http://site.com/images/image.png';

How do I save file from remote site to my own into some folder?

Community
  • 1
  • 1
James
  • 42,081
  • 53
  • 136
  • 161
  • I think someone asks this every day. http://stackoverflow.com/search?q=php+save+remote+file+locally only 34 pages... – DampeS8N Dec 08 '10 at 14:41

3 Answers3

8
copy($image_url, $your_path);

And if allow_url_fopenin your php.ini is not set, then get the file with cURL.

rik
  • 8,592
  • 1
  • 26
  • 21
5

You can do this with CURL. From the manual:

$ch = curl_init("http://site.com/images/image.png");
$fp = fopen("image.png", "w");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
fclose($fp);
Paul Schreiber
  • 12,531
  • 4
  • 41
  • 63
2
$image_url = 'http://site.com/images/image.png';
$img = file_get_contents($image_url);
$fp = fopen('image.png', 'w');
fwrite($fp, $img);
fclose($fp);
mrwooster
  • 23,789
  • 12
  • 38
  • 48