百度百家图片上传php实现

QQ截图20171104140324.jpg

不废话 上代码

function upload_img($file){
    global $header;
    $url = 'http://rsbjh.baidu.com/builderinner/api/content/file/upload?encode=utf-8&is_waterlog=1&type=image&app_id=xxxxxx&usage=content';
    /    //echo "Upload file:".$file ."\n";
    $fields['media'] = '@'.$file;

    $fields['id'] = "WU_FILE_0";
    $fields['name'] = $file;
    $fields['type'] = "image";
  

$header="";
$header[]="Content-Type:multipart/form-data; 
Cookie:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Host:rsbjh.baidu.com
Origin:http://baijiahao.baidu.com
Referer:http://baijiahao.baidu.com/builder/content/static/third_party/ueditor/dialogs/
User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0";
print_r($header);

print_r($fields);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url );
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt ( $ch, CURLOPT_HEADER, 0 ); 
    curl_setopt ( $ch, CURLOPT_HTTPHEADER, $header );     
    curl_setopt($ch, CURLOPT_POST, 1 );
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 

    $opres= curl_exec( $ch );

    if ($error = curl_error($ch) ) {
      die($error);
      return false;
    }
    curl_close($ch); 
 
    return  $opres_o;

}


暂无留言,赶快评论吧

欢迎留言