Using Google Docs Viewer to preview documents online

Categories PHP, PHP Code Generator, PHP Form Generator, Tutorials

Google Docs Viewer provides an excellent option to preview Office documents online. No need to download them to end user machine, no need to have any Office software installed. Supported formats are Microsoft Word, Microsoft Excel and PDF.


Syntax is quite simple:
https://docs.google.com/viewer?url=<url of your document>

Today we'll see how you can use this feature in PHPRunner applications. In PHPRunner you have two upload options: Basic and Advanced upload controls. In both cases you need to set 'View as' type of upload field to custom.

Basic upload control:

$value = "<a target=_blank href='https://docs.google.com/viewer?url=http://demo.asprunner.net/volinrok_yahoo_com/Project2/files/".$value."'>".$value."</a>";

Replace http://demo.asprunner.net/volinrok_yahoo_com/Project2/files/ with path to the folder where your files are stored.

Advanced upload control:

$fileArray = my_json_decode($value);
$value="";
for($i = 0; $i < count($fileArray); $i++)
{
	$value .= "<a target=_blank href='https://docs.google.com/viewer?url=http://demo.asprunner.net/volinrok_yahoo_com/Project2/".$fileArray[$i]["name"]."'>".
		$fileArray[$i]["usrName"]."</a> ";
}

Replace http://demo.asprunner.net/volinrok_yahoo_com/Project2/ with the path of your web application.

This is it. Enjoy!

1 thought on “Using Google Docs Viewer to preview documents online

  1. I read that it allows file only up to 25 MB ?
    is that correct, yes than is there any way to increase ?
    Thanks & regards

Leave a Reply

Your email address will not be published. Required fields are marked *