Php 文件\u获取\u内容导致我无法打开流

Php 文件\u获取\u内容导致我无法打开流,php,arrays,url,download,Php,Arrays,Url,Download,我有简单的CI(CodeIgniter)代码。我想做的是:当我输入textarea的图片路径时,php将每张图片下载到我的服务器并给它们文件名,但我有以下错误: Message: file_get_contents(http://geosmiley.ge/Upload/Product/42/1.jpg ) [function.file-get-contents]: failed to open stream: Invalid argument Message: file_get_content

我有简单的CI(CodeIgniter)代码。我想做的是:当我输入textarea的图片路径时,php将每张图片下载到我的服务器并给它们文件名,但我有以下错误:

Message: file_get_contents(http://geosmiley.ge/Upload/Product/42/1.jpg ) [function.file-get-contents]: failed to open stream: Invalid argument

Message: file_get_contents(http://geosmiley.ge/Upload/Product/42/2.jpg ) [function.file-get-contents]: failed to open stream: Invalid argument
这是我的CI代码:

$image = explode("\n", $_POST['images']);
for ($i = 0; $i < count($image); $i++){
    if (substr($image[$i], 0, strlen($this->host) - 1) != $this->host){
        file_put_contents('images/'.$title_url.'_'.$i.'.jpg', file_get_contents($image[$i]));
        $image[$i] = $this->host.'/images/'.$title_url.'_'.$i.'.jpg';                                
    }
}
$poster = $image[0];
$images = implode("\n", $image);
$image=explode(“\n”,$\u POST['images']);
对于($i=0;$ihost)-1)!=$this->host){
文件内容('images/'.$title\uurl.'.$i..jpg',文件内容($image[$i]);
$image[$i]=$this->host./images/.$title\u url.''.$i..jpg';
}
}
$poster=$image[0];
$images=内爆(“\n”,$image);
它所做的只是下载最后一个文件,而对于第一个和第二个文件,它会给出该错误


请不要给我其他的建议,比如使用卷曲的fopen。我认为这是正确的方法,因为php成功下载了最后一个文件。请帮我解决我的问题

将你的URL用引号括起来;让它成为一个字符串

将你的URL用引号括起来;从以下位置将其设置为字符串

如果fopen 包装器已启用

您需要将
allow\u url\u fopen
设置为true,或者改为使用。

来自:

如果fopen 包装器已启用


您需要将
allow\u url\u fopen
设置为true,或者改用。

我不知道问题发生的原因,但下面是修复问题的代码,感谢“NikiC”发现witespace“”是问题所在,我修复了它

此代码不起作用

$image=explode(“\n”,$\u POST['images']);
对于($i=0;$ihost)-1)!=$this->host){
文件内容('images/'.$title\uurl.'.$i..jpg',文件内容($image[$i]);
$image[$i]=$this->host./images/.$title\u url.''.$i..jpg';
}
}
$poster=$image[0];
$images=内爆(“\n”,$image);
这是工作代码

$image=explode(“\n”,$\u POST['images']);
对于($i=0;$ihost)-1)!=$this->host){
如果($idownload($kk,'images/.$title_url.''.$i..jpg')){
$image[$i]=$this->host./images/.$title\u url.''.$i..jpg';
}否则{
回声($image[$i]);
}
}
}
//****************************************************
公共函数下载($url,$path){
if(file_put_contents($path,file_get_contents($url)){return TRUE;}else{return FALSE;}
}

我不知道为什么会出现问题,但下面是修复问题的代码,感谢“NikiC”发现witespace“”是问题所在,我修复了它

此代码不起作用

$image=explode(“\n”,$\u POST['images']);
对于($i=0;$ihost)-1)!=$this->host){
文件内容('images/'.$title\uurl.'.$i..jpg',文件内容($image[$i]);
$image[$i]=$this->host./images/.$title\u url.''.$i..jpg';
}
}
$poster=$image[0];
$images=内爆(“\n”,$image);
这是工作代码

$image=explode(“\n”,$\u POST['images']);
对于($i=0;$ihost)-1)!=$this->host){
如果($idownload($kk,'images/.$title_url.''.$i..jpg')){
$image[$i]=$this->host./images/.$title\u url.''.$i..jpg';
}否则{
回声($image[$i]);
}
}
}
//****************************************************
公共函数下载($url,$path){
if(file_put_contents($path,file_get_contents($url)){return TRUE;}else{return FALSE;}
}


是否打开了“允许打开url”?“Tandu”我不允许使用fopen,出于安全考虑,您不能将URL与
文件内容一起使用。它还需要打开该设置。可能的重复请查看我修改的代码,这可以帮助您帮助我,PLZZ是否打开了“允许打开url”?“Tandu”我不允许使用fopen,出于安全考虑,您不能将URL与
文件内容一起使用。它还需要打开该设置。可能重复的请查看我修改的代码,这可以帮助你帮助我,plzzlooks像你是对的,但我很好奇,因为他给url提供了一个可变的文件内容($image[$I]),为什么需要引号?我尝试了文件内容(“.”.$image[$I]”);但是没有用请看我修改过的代码,它可以帮助你帮助我,看起来你是对的,但我很好奇,因为他给了url一个可变的文件内容($image[$I]),为什么需要引号?我试过文件内容('''.$image[$I]');但不工作请看我修改过的代码,这可以帮助你帮助我,我想知道为什么我的代码不工作?我犯了什么错误?您需要检查php.ini中的
allow\u url\u fopen
设置。如果设置不正确,
file\u get\u contents
将失败。@user939421正如webbiedave提到的,它可能在您的服务器端被禁用,请检查您的phpinfo或使用cURL扩展请查看我修改的代码,这可以帮助您帮助我,请按照webbiedave所说的做。制作一个只运行
的PHP脚本,并检查
是否设置了允许url\u fopen
。我想知道为什么我的代码没有设置
$image = explode("\n", $_POST['images']);
for ($i = 0; $i < count($image); $i++){
    if (substr($image[$i], 0, strlen($this->host) - 1) != $this->host){
        file_put_contents('images/'.$title_url.'_'.$i.'.jpg', file_get_contents($image[$i]));
        $image[$i] = $this->host.'/images/'.$title_url.'_'.$i.'.jpg';                                
    }
}
$poster = $image[0];
$images = implode("\n", $image);
$image = explode("\n", $_POST['images']);
for ($i = 0; $i < count($image); $i++){
    if (substr($image[$i], 0, strlen($this->host) - 1) != $this->host){
        if ($i < count($image)-1){
            $kk = substr($image[$i], 0, strlen($image[$i]) - 1);
        } else {
            $kk = $image[$i];
        }
        if ($this->download($kk, 'images/'.$title_url.'_'.$i.'.jpg')){
            $image[$i] = $this->host.'/images/'.$title_url.'_'.$i.'.jpg';
        }else{
            echo($image[$i]);
        }
    }
}
//****************************************************
    public function download($url, $path){
        if (file_put_contents($path, file_get_contents($url))){return TRUE;}else{return FALSE;}
    }