1

I have to copy JPG from an external server, such as Facebook, to my server.

What is the best way to do so? I though maybe with fread/fopen etc. but I don't know if it is the best way.

Bobrovsky
  • 13,274
  • 19
  • 77
  • 125
Pierre Lebon
  • 415
  • 1
  • 5
  • 12
  • This should cover it Along with a few issues http://stackoverflow.com/questions/3938534/download-file-to-server-from-url – Mark Jones Feb 11 '13 at 13:02
  • Read the [documentation](http://www.php.net/manual/en/index.php). Almost everything you want to know about PHP can be found there. – Sverri M. Olsen Feb 11 '13 at 13:09

2 Answers2

3

You can use URLs with most filesystem functions (like copy).

$url = "http://cdn.sstatic.net/stackoverflow/img/sprites.png";
$target = "/tmp/stackoverflow.png";
copy($url, $target);

Do note that you need to have the php.ini setting allow_url_fopen enabled.

BenMorel
  • 31,815
  • 47
  • 169
  • 296
Arnold Daniels
  • 16,200
  • 4
  • 49
  • 79
1
 $url = 'http://facebook.com/image.jpg';

 $img = '/my/folder/image.jpg';

 file_put_contents($img, file_get_contents($url));
Edwin Alex
  • 5,048
  • 4
  • 27
  • 49
Husman
  • 6,579
  • 7
  • 28
  • 46