PHP-cURL文件上传生成415个http代码
我正在尝试使用POST将图像文件上载到RESTful API,但没有html表单,我遇到了一些问题PHP-cURL文件上传生成415个http代码,php,image,rest,curl,file-upload,Php,Image,Rest,Curl,File Upload,我正在尝试使用POST将图像文件上载到RESTful API,但没有html表单,我遇到了一些问题 $data_string = "@../upload_files/images/".$data.";type=image/png"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST
$data_string = "@../upload_files/images/".$data.";type=image/png";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CERTINFO, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$http_headers = array(
'Content-Type: image/png'
);
if (isset($_SESSION['Auth']))
$http_headers[] = 'Authorization: Bearer '.$_SESSION['Auth'];
curl_setopt($ch, CURLOPT_HTTPHEADER, $http_headers);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
这将返回一个HTTP代码415,并且$info中定义的内容类型为null,即使我定义了它。这里是否有我遗漏的内容,或者无法将未通过html表单上载的图像发布到服务器?您应该指定上载文件的完整绝对路径/upload_files/images/是一个相对路径。那么会是吗?用于将相对路径转换为绝对路径我已经尝试过了,但仍然没有成功。还有什么别的吗?