curl 模仿上传文件

2019-04-15 17:54发布

$params=array(); $params['file'] = curl_file_create('/home/user/Documents/pic/12.jpg', 'image/jpg','file'); $ch = curl_init(); $options = array( CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_HEADER => false, CURLOPT_NOBODY => false, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_URL => "https://www.xxx.com/" . $api_name, CURLOPT_POSTFIELDS => $params ); curl_setopt_array($ch, $options); $result = curl_exec($ch); curl_close($ch); var_dump($result); $result_arr = json_decode($result, true); if (!$result_arr) { return $result; } else { return $result_arr; }