接口接收 域名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格式的)
请求大神点拨
最佳答案