Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP-cURL文件上传生成415个http代码_Php_Image_Rest_Curl_File Upload - Fatal编程技术网

PHP-cURL文件上传生成415个http代码

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

我正在尝试使用POST将图像文件上载到RESTful API,但没有html表单,我遇到了一些问题

$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/是一个相对路径。那么会是吗?用于将相对路径转换为绝对路径我已经尝试过了,但仍然没有成功。还有什么别的吗?