【发布时间】:2012-01-13 21:12:14
【问题描述】:
我有简单的 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);
它所做的只是下载最后一个文件,而对于第一个和第二个文件,我会遇到这个错误
请不要给我其他建议,例如使用 fopen 的 cURL。我认为这是正确的方法,因为 php 成功下载了 LAST FILE。请帮我解决我的问题
【问题讨论】:
-
“allow_fopen_url”是否开启? php.net/manual/en/…
-
"Tandu" 为了安全起见,我不会允许 fopen
-
那么您不能使用带有
file_get_contents的网址。它还需要打开该设置。 -
请看我修改后的代码,可以帮到你,plzz