Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将远程映像保存到本地服务器Codeigniter_Php_Codeigniter - Fatal编程技术网

Php 将远程映像保存到本地服务器Codeigniter

Php 将远程映像保存到本地服务器Codeigniter,php,codeigniter,Php,Codeigniter,我正在尝试使用Codeigniter中的Phils Curl srcipt将远程映像保存到本地服务器 要确保目录在那里并具有适当的权限,请执行以下操作: if (!is_dir('images')){ mkdir('./images', 0777, true); } 这是我试过的。。() 它正在创建一个名为main.jpg但包含0字节的文件 我还尝试使用复制和文件获取内容 if ( ! copy($localURL, $img)){ $error = get_last_error();

我正在尝试使用Codeigniter中的Phils Curl srcipt将远程映像保存到本地服务器

要确保目录在那里并具有适当的权限,请执行以下操作:

if (!is_dir('images')){
  mkdir('./images', 0777, true);
}
这是我试过的。。()

它正在创建一个名为main.jpg但包含0字节的文件

我还尝试使用复制和文件获取内容

if ( ! copy($localURL, $img)){
  $error = get_last_error();   
  $this->session->set_flashdata('err_message', $error['message']);
}


if ( ! file_put_content($localURL, file_get_content($img) )){
  $error = get_last_error();   
  $this->session->set_flashdata('err_message', $error['message']);
}

但是它也不能正常工作,它没有给出任何错误信息

我首先调试$img数据,验证它是否有一堆二进制垃圾。您可能还需要检查http状态。也许网站拒绝用户代理远程卷发。

这样做怎么样

  $remoteFile = 'http://fermeteogranada.com/camara.jpg';
  $remoteResource = file_get_contents($remoteFile);

  $saveTo = './images/main.jpg';
  file_put_contents($saveTo, $remoteResource);

我在本地试用过,效果很好。

我正在Windows上的本地试用。。。我试过了,它对我不起作用!!您的php.ini中的“allow\u url\u fopen”是否设置为“true”?如果不是,那就是你的问题;-)是的,它设置正确。我的php.ini.OK中有
'allow\u url\u fopen'=on
。我试图得到一些错误信息,这就是我得到的<代码>消息:文件\u获取\u内容(http://fermeteogranada.com/camara.jpg)[function.file get contents]:无法打开流:连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机没有响应。
  $remoteFile = 'http://fermeteogranada.com/camara.jpg';
  $remoteResource = file_get_contents($remoteFile);

  $saveTo = './images/main.jpg';
  file_put_contents($saveTo, $remoteResource);