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,789
  • 19
  • 80
  • 130
Pierre Lebon
  • 445
  • 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
  • 34,448
  • 50
  • 182
  • 322
Arnold Daniels
  • 16,516
  • 4
  • 53
  • 82
1
 $url = 'http://facebook.com/image.jpg';

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

 file_put_contents($img, file_get_contents($url));
Edwin Alex
  • 5,118
  • 4
  • 28
  • 50
Husman
  • 6,819
  • 9
  • 29
  • 47