Save remote file [duplicate]
Possible Duplicate:
PHP save image file
$image_url = 'http://site.com/images/image.png';
How do I save file from remote site to my ow开发者_C百科n into some folder?
copy($image_url, $your_path);
And if allow_url_fopen
in your php.ini is not set, then get the file with cURL.
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);
$image_url = 'http://site.com/images/image.png';
$img = file_get_contents($image_url);
$fp = fopen('image.png', 'w');
fwrite($fp, $img);
fclose($fp);
精彩评论