file_get_contents()无法打开流:与php变量一起使用时没有这样的文件或目录


file_get_contents() failed to open stream: No such file or directory while using with php variable

我在两种情况下使用file_put_contents

情况1:

file_put_contents("album/$i.jpg", file_get_contents("http://www.lightscamerabollywood.com/wp-content/uploads/2012/02/Deepika-Padukone-movie-list-Aishwarya.jpg"));

在这种情况下,它工作得很好。

情况2:

$fp = fopen('urls.txt', 'r');  
$i =1;  
while ($url = fgets($fp)) {  
file_put_contents("album/$i.jpg", file_get_contents($url));  
$i++;  
}

但在这种情况下,它抛出错误:

file_get_contents()无法打开流:没有这样的文件或目录

$fp = fopen('urls.txt', 'r');
$i = 1;
while ($url = fgets($fp)) {
    file_put_contents("album/$i.jpg", file_get_contents(rtrim($url)));
    $i++;
}
die;