文件上传到接口问题

浏览:1740 发布日期:2015/05/23 分类:求助交流 关键字: 文件上传到接口 $_FILE直接上传接口 图片上传 接口
公司开发了一个项目,提供给我们接口,我写手机Web端口的,这里有个头像上传的问题。

接口接收 域名1/index.php?m=Api&c=index&a=upload_head_pic 接收$_FILE类型的POST

webAPP(自己开发) 域名2/index.php?m=&c=&a= 这里有一个form文件上传表单


现在要webAPP控制器端接收$_FILE 然后再传到接口 要怎么实现?

网上找了一个
function upload($imgpath,$ext){
$url='http://'.C('DO_MAIN').'/index.php?m=Api&c=index&a=upload_head_pic';
$header = array();
$header[] = 'Content-Type:'.$ext;
$post_data = file_get_contents($imgpath); // raw_post方式
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
$out = curl_exec($ch);
curl_close($ch);
return $out;
}


这里的$imgpath 要传入文件位置
可是$_FILE根本不是文件位置 ,我想传入$_FILE['img']['tmp_name'],但是这个临时存储文件根本不是.jpg格式的(上传时是jpg格式的,$_FILE['img']['type']显示也是jpg格式的)
请求大神点拨
最佳答案
评论( 相关
后面还有条评论,点击查看>>