Crm Expert
Crm Expert

Upload File To Zoho Docs Using PHP

21.08.19 09:54 PM

After searching for php code to upload file to zoho docs via API, and couldent get a working example, here is a working code, hope it will help you as well.

The upload file documentation can be found here 

I did not use 2 optional parameters which are avaliable, so this code will upload the file to your root folder.


<?php
$AUTHTOKEN='YOUR TOKEN';
$path='/var/myfolder';
$filename='myFileName.txt';
$fullPath=$path."/".$filename;
$url = "https://apidocs.zoho.com/files/v1/upload?authtoken=".$AUTHTOKEN."&scope=docsapi";
$fields = array(
            'filename' => $filename,
            'content' => curl_file_create ($fullPath)
        );

$ch = curl_init();

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_URL, $url );
$result = curl_exec($ch);
curl_close($ch);
?>