使用PHP Curl将文件上传到Zoho API [英] Uploading files to Zoho API with PHP Curl

查看:253
本文介绍了使用PHP Curl将文件上传到Zoho API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用ZohoCRM API将文件附加到Zoho CRM帐户页面,但没有取得任何成功。我使用Curl和PHP5.3(没有curl_file_create,所以使用手滚动版本)。

I am trying to attach a file to a Zoho CRM Account page using the ZohoCRM API and not having any success. I am using Curl and PHP5.3 (no curl_file_create, so using hand rolled version).

在我的日志中,我得到以下报告

In my log I get the following report

Curl::post 
Url: https://crm.zoho.com/crm/private/json/Accounts/uploadFile?authtoken=MY_TOKEN&scope=crmapi
Params: Array(
    [content] => @/tmp/b2d-JbJvMY;filename=b2d-JbJvMY;type=application/pdf
    [id] => MY_ACCOUNT_ID
)



我没有收到ZohoCRM的回应,目标帐户记录。

I get no response from ZohoCRM and the file is definitely not attached to the target Account record. What am I doing wrong?

这里是我的代码中可能有助于或阻碍的一些摘录:...我的ZohoAPI类的其他方法,如getSearchRecords似乎工作正常...

Here's some excerpts from my code that may help or hinder: ... other methods from my ZohoAPI class such as getSearchRecords appear to be working fine...

class Curl {
...
protected static function post($url, $params) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER,0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}
...
}


class ZohoAPI extends Curl {
....
protected function apiPost($url, $params) {
    $url .= "?authtoken={$this->token}&scope={$this->scope}";
    $apiParams = empty($params) ? '' : $params;
    return $this->post($url, $apiParams);
}
...
public function uploadFile($module='Accounts', $zohoId = '', $file ) {
    $url = "{$this->apiUrl}/{$this->mode}/{$module}/uploadFile";
    $params = array(
        'content' => curl_file_create($file, 'application/pdf' , basename( $file, '.pdf')),
        'id' => $zohoId
    );

    return $this->apiPost($url, $params);
}
...
}


推荐答案

尝试上传文件时,请检查您是否有权限执行此操作: - (

When trying to upload a file, check you have permission to do so :-(

退出我尝试上传的文件不能为由过程读取。

Turns out the file I was trying to upload could not be read by the process.

这篇关于使用PHP Curl将文件上传到Zoho API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆