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
  • 38,737
  • 52
  • 130
  • 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,449
  • 1
  • 23
  • 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,352
  • 4
  • 37
  • 62
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,019
  • 11
  • 35
  • 46