如何在php中使用curl发布图像

如何在php中使用curl发布图像,php,curl,zend-framework,socialengine,Php,Curl,Zend Framework,Socialengine,我想更改配置文件映像另一个应用程序curl请求我正在尝试下面的代码有人能帮我吗 $viewer = Engine_Api::_()->user()->getViewer(); $apiData = array( "email" => $viewer->email, "profile_image_file" => $_FILES['Filedata']['name'], ); $apiHost = "https://tenant.thetenantsnet.

我想更改配置文件映像另一个应用程序curl请求我正在尝试下面的代码有人能帮我吗

$viewer = Engine_Api::_()->user()->getViewer();

$apiData = array(
  "email" => $viewer->email,
  "profile_image_file" => $_FILES['Filedata']['name'],
);
$apiHost = "https://tenant.thetenantsnet.co.uk/api/api/save_profile_image";

$response = $this->callRiseAPI2($apiData,$apiHost);

   private function callRiseAPI2($apiData,$apiHost){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $apiHost);
        curl_setopt($ch, CURLOPT_POST, count($apiData));
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($apiData));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        $jsonData = curl_exec($ch);
        if (false === $jsonData) {
            throw new \Exception("Error: _makeOAuthCall() - cURL error: " . curl_error($ch));
        }
        curl_close($ch);

        //return the API response 
        return json_decode($jsonData);
  }

正如Anoxy所说,您需要在标题中输入内容类型:

$viewer = Engine_Api::_()->user()->getViewer();

$apiData = array(
  "email" => $viewer->email,
  "profile_image_file" => $_FILES['Filedata']['name'],
);
$apiHost = "https://tenant.thetenantsnet.co.uk/api/api/save_profile_image";

$response = $this->callRiseAPI2($apiData,$apiHost);

   private function callRiseAPI2($apiData,$apiHost){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $apiHost);
        curl_setopt($ch, CURLOPT_POST, count($apiData));
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($apiData));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_HTTPHEADER, 'Content-Type: multipart/form-data');

        $jsonData = curl_exec($ch);
        if (false === $jsonData) {
            throw new \Exception("Error: _makeOAuthCall() - cURL error: " . curl_error($ch));
        }
        curl_close($ch);

        //return the API response 
        return json_decode($jsonData);
  }

你很接近。您需要指定标题:“内容类型:多部分/表单数据”是的,我放置了标题,但它没有发布电子邮件,然后:(