首先是先把远程附件的附件设置配置好,可以选择阿里云、腾讯云、七牛。
1.先写好一个上传图片至远程的方法
//.....将这个代码封装在一个方法里
public function doremoteupload($pathname)
{//远程上传代码
global $_GPC, $_W;
load()->func('file');
//$pathname = 'images/6/2015/12/gT1aQZ5WA1UAZu58ntKUa1Rkw811K8.jpg';
if (!empty($_W['setting']['remote']['type'])) { // 判断系统是否开启了远程附件
$remotestatus = file_remote_upload($pathname); //上传图片到远程
if (is_error($remotestatus)) {
message('远程附件上传失败,请检查配置并重新上传')
} else {
$remoteurl = tomedia($pathname); // 远程图片的访问URL
//$pathname // 本地要存入库的地址
}
}
}
2.在表单提交的接口处理中调用方法
if (!empty($_GPC['img_list'])) {
//远程上传
// $img_list= $_GPC['img_list'];
for($i = 0;$i<count($_GPC['img_list']);$i++){
$this->doremoteupload($_GPC['img_list'][$i]);
}
}
如果不过详细,可以参考微擎.看云:
远程附件