保存远程文件

保存远程文件

问题描述:

可能重复:
PHP save image file保存远程文件

$image_url = 'http://site.com/images/image.png'; 

如何保存从远程站点文件我自己到某个文件夹?

+0

我想有人问这个每一天。 http://*.com/search?q=php+save+remote+file+locally只有34页... – DampeS8N 2010-12-08 14:41:23

copy($image_url, $your_path); 

如果在php.ini allow_url_fopen没有设置,然后拿到文件,cURL

+0

PHP 4.3.0或以上版本。 – thejh 2010-12-08 14:41:37

+0

如果文件太大,请尝试使用Paul Schreiber提到的卷曲方法 – 2016-10-27 11:57:37

$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);