在PHP Curl中发布数据

时间:2011-11-14 14:49:45

标签: php post file-upload curl zoho

我正在尝试使用PHP CURL将内容作为参数发布到文件中。

数据已发布,但Zoho打开了一个空白文档,而不是我要打开的文档。

我相信它是因为我提供了$post_data['content']变量的无效输入。

$post_data['content'] = "@/c:/xampp/htdocs/site/a.doc";

根据ZOHO API中的内容,当收到的内容为空时,Zoho会打开一个空白文档。

我的代码在下面给出以供参考。     <

?php   
        $post_data['content']  = "@/c:/xampp/htdocs/site/a.doc";
        $post_data['apikey']   = '[MY API KEY IS HERE]';
        $post_data['output']   = 'url';
        $post_data['filename'] = "a.doc";
        $post_data['id']       = '12345678';
        $post_data['format']   = "doc";
        $post_data['saveurl']  = 'https://localhost/researchPortal/tmp/save.php';
        $post_data['agentname'] = 'ZRemoteAgent';
        $post_data['mode']   = "normaledit";

        foreach ( $post_data as $key => $value)
        {
            $post_items[] = $key . '=' . $value;
        }

        $post_string = implode ('&', $post_items);



    //create cURL connection
$curl_connection =  curl_init('https://exportwriter.zoho.com/remotedoc.im');

//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,  "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);

//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

//perform our request
$result = curl_exec($curl_connection);

                echo $result;

//close the connection
curl_close($curl_connection);

?>

1 个答案:

答案 0 :(得分:2)

我的猜测是改变

curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_data);

我猜测将其转换为字符串是因为卷曲不会使用魔法@上传文件 http://dtbaker.com.au/random-bits/uploading-a-file-using-curl-in-php.html