的file_get_contents给我未能打开流
我有简单的CI(codeIgniter)code。我想要做的是:当我输入图片的路径textarea的,PHP下载的每一张图片到我的服务器,并给他们的文件名,但我有这些错误:
I have simple CI (CodeIgniter) code. what I want to do is: when I enter the pictures path to textarea, php downloaded each picture to my server and gave them filenames, but I have these errors:
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 code:
Here is my CI code:
$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);
它所做的仅仅是下载并为第一和第二档最后的文件给我的错误的
What it does is simply downloads last file and for first and second files gives me that error
请不要给我其他方面的建议喜欢使用的fopen卷曲。我认为这是正确的做法,因为PHP下载LAST文件成功。请帮我解决我的问题。
and please don't give me other advice like using cURL of fopen. I think that it is correct way because php downloads LAST FILE successfully. Please help me to solve my problem
我不知道为什么发生问题,但这里是code,它固定它,这要归功于NikiC谁发现了witespace是问题,我固定它。
I don't know Why the problem happened but here is the code that fixed it, thanks to "NikiC" who found out that witespace " " was the problem, I fixed it.
这code不起作用的
This Code doesn't work
$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);
这是工作code 的
This is working code
$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;}
}