从其他服务器下载文件 php

Download files from other server php

我在将文件复制到本地服务器时遇到问题。我只有最后一个文件 plashka_3.png。

Warning: copy(http://rus-yurist.ru/images/plashka_1.png ) [function.copy]: failed to open stream: HTTP request failed!

Warning: copy(http://rus-yurist.ru/images/plashka_2.png ) [function.copy]: failed to open stream: HTTP request failed!

$txt="http://rus-yurist.ru/images/plashka_1.png
      http://rus-yurist.ru/images/plashka_2.png
      http://rus-yurist.ru/images/plashka_3.png";

$a1=explode("\n",$txt);
$a1=array_unique($a1);

foreach($a1 as $url) {
    $ch = curl_init($url); 
    $path_parts = pathinfo($url); 
    $path = 'docs/'.$path_parts['basename'];
    copy($url, $path);
 //  file_put_contents($path, file_get_contents($url)); /* not works too, only last file
}

我一直用file_put_contents

file_put_contents("Tmpfile.zip", fopen("http://someurl/file.zip", 'r'));

我应该 trim 我的 $url 变量!感谢杰罗恩!