时间:2021-07-01 10:21:17 帮助过:2人阅读
$size = filesize($path);//文件大小
$ch = curl_init($url);
$cfile = curl_file_create($path);
if (is_null($post_data)) {
$data = array('media' => $cfile);
}else{
$data = array('media' => $cfile,'description'=>$post_data);
}
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_INFILESIZE,$size);
curl_setopt($ch, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
$info = curl_exec($ch);
if (curl_errno($ch)) {
var_dump(curl_errno($ch));
return FALSE;
}
curl_close($ch); // 关闭CURL会话
return $info; // 返回数据
我查看手册后使用过CURLFile函数,但返回的错误依然是26错误码,或者是缺少多媒体问题等
$cfile = new \CURLFile($path,$upload_type,$upload_name);