开发者

Save remote file [duplicate]

This question already has answers here: Closed 12 years ago.

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_fopenin 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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜