保存远程文件
问题描述:
$image_url = 'http://site.com/images/image.png';
如何保存从远程站点文件我自己到某个文件夹?
答
$image_url = 'http://site.com/images/image.png';
$img = file_get_contents($image_url);
$fp = fopen('image.png', 'w');
fwrite($fp, $img);
fclose($fp);
答
你可以用CURL来做到这一点。从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);
我想有人问这个每一天。 http://*.com/search?q=php+save+remote+file+locally只有34页... – DampeS8N 2010-12-08 14:41:23