Using Zoho Remote API in PHP to edit office documents on your LAMP server
Check out the new site at https://rkblog.dev.
9 October 2009
Comments
Using Zoho Remote API with Python is quite similar to using it with PHP. In both languages we use the CURL library. In PHP the usage of curl is a bit different
Requirements
- Zoho API key
- PHP hosting with CURL support
Remote API for Zoho Writer
Here is an example script that will open local document in Zoho Editor:<?php
$api = 'Your API KEY';
$fields = array();
$fields['content'] = "@/path/to/file.odt";
$fields['filename'] = 'file.odt';
$fields['id'] = '13';
$fields['format'] = 'odt';
$fields['saveurl'] = urlencode('http://localhost/foo.php');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://export.writer.zoho.com/remotedoc.im?apikey='.$api.'&output=editor');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$page = curl_exec($ch);
curl_close($ch);
echo $page;
Remote API for Sheet and Show
Remote API for Sheet and Show is bit simpler. In this case the API won't return JS code that opens the editor, but will send the URL to the editor in Location response header. So we have to get the header:<?php
$api = 'Your API KEY';
$fields = array();
$fields['content'] = "@/path/to/b.ppt";
$fields['filename'] = 'b.ppt';
$fields['id'] = '13';
$fields['format'] = 'ppt';
$fields['saveurl'] = urlencode('http://localhost/foo.php');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://show.zoho.com/remotedoc.im?apikey='.$api.'&output=editor');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, true);
$content = curl_exec ($ch);
curl_close ($ch);
$headers = explode("
", $content);
foreach($headers as $val)
{
if (stripos($val, 'Location: ') !== false)
{
$url = str_replace('Location: ', '', $val);
echo '<iframe src="'.$url.'" style="width:100%;height:400px;"></iframe>';
}
}
RkBlog
Check out the new site at https://rkblog.dev.
Comment article