copy() 警告文件名不能为空


copy() Warning Filename cannot be empty

我正在尝试将外部图像保存在我的网站上

我有这个代码:

$file = $_GET['url'];
$newfile = $_SERVER['DOCUMENT_ROOT'] . '/images/name.jpg';
if ( copy($file, $newfile) ) {
    echo "Copy saved";
}else{
    echo "copy failed";
}

它运行良好并将图像保存在我的服务器上正常,但是当我尝试在 FOR 内部使用时,我有以下警告:

Warning: copy(): Filename cannot be empty in /home/animesad/public_html/bot/getimg.php on line 18

我的代码是:

<?php
require "../functions.php";
$p = $_GET['p'];
$url = "http://www.mysite.net/en/movie/page/".$p."/";
$source = curl_get_contents("$url");
preg_match_all('#<li title="(.*?)"><a href#',$source,$name); //outputs title post
preg_match_all('#<img src="(.*?)" width="140" height="200"/>#',$source,$img); //outputs img url
for($i=0;$i<10;$i++){
//print_r($name[1][$i]."<hr />");  //that code show the names OK. (Title posts);
$namefile = slugify($name[1][$i]); //slugify is my function that convert titles in slug.
$newfile = $_SERVER['DOCUMENT_ROOT'] .'/img/'.$namefile.'.jpg';
    if ( copy($file, $newfile) ) {
        echo "copy saved <hr />";
    }else{
        echo "copy failed <hr />";
    }
}
?>

欢迎任何想法。

你忘了你的$file

$file = $_GET['url'];
for($i=0;$i<10;$i++){
    $namefile = slugify($name[1][$i]); //slugify is my function that convert titles in slug.
    $newfile = $_SERVER['DOCUMENT_ROOT'] .'/img/'.$namefile.'.jpg';
    if ( copy($file, $newfile) ) {
        echo "copy saved <hr />";
    }else{
        echo "copy failed <hr />";
    }
}