curl http post 数据和图片

curl http post 数据和图片
2010-11-17 14:47
 add_post_tips($url,$port=80,$content,$upload_arr){    

$boundray = time();    
$h   = array();
$m_line="\r\n";
//准备头和XML文档    
$h[] = "Content-Type:  multipart/form-data; boundary=".$boundray;    
$h[] = "Connection: Keep-Alive";

$t = array();
$t[] = "--".$boundray;
$t[] = "Content-Disposition: form-data; name=\"UPLOAD_IDENTIFIER\"".$m_line;
$t[] = "34f4eec9d2922ab59d23c8b02291dd4f";    
$t[] = "--".$boundray;
$t[] = "Content-Disposition: form-data; name=\"json\"".$m_line;
$t[] = $content;
$t[] = "--".$boundray;
$t[] = "Content-Disposition: form-data; name=\"File_1\"; filename=\"".$upload_arr['name']."\"";
$t[] = "Content-Type: image/jpeg".$m_line.$m_line;    
$c = implode($m_line,$t); 
//准备二进制内容
$upload_fp = fopen($upload_arr['tmp_name'], "rb");
while(!feof($upload_fp)) {
$file_piece = fread($upload_fp, 4096);
$c .= $file_piece;                    
}        
fclose($upload_fp);

$c .=$m_line."--".$boundray;    

// create a new cURL resource
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PORT, $port);
curl_setopt($ch, CURLOPT_HTTPHEADER, $h);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $c);    
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$rsp = curl_exec($ch);    
return ($rsp);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值