/**
* @param string $url 远程地址
* @param array $param 需要提交的参数
* @param string $filename 上传文件名
* @param int $wait 等待响应时间
* @return array|bool
* 请求-提交数据 使用post方式提交
*/
function FCurl_post($url, $param = array(), $filename = '', $wait = 30)
{
if (!is_array($param)) {
return false;
}
if($filename){
if($_FILES[$filename]['name']){
$param['file'] = new \CURLFile($_FILES[$filename]['tmp_name'], $_FILES[$filename]['type'], $_FILES[$filename]['name']);
}
}
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => $wait,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $param, // 直接将参数数组作为POST数据
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
),
));
if (strpos($url, "https") === 0) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
$response = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$err = curl_error($curl);
curl_close($curl);
$result = array(
'response_code' => $httpCode,
'output' => $response,
);
return $result;
}
$arr = [
'title'=>$data['title'],
'keywords'=>$data['keywords'],
'description'=>$data['description'],
'content'=>$data['content'],
'status'=>$data['status'],
'orderSort'=>$data['orderSort'],
'downloadJur'=>$data['downloadJur'],
];
使用示例:FCurl_post('https://www.9wdn.com/test',$arr,'filename');
发表评论