How To Display Word Document In Browser In Localhost?
Solution 1:
You can't. Browsers don't have any built-in way to view Word docs so unless the user has configured their browser to open it with some plugin (which 99% of the world hasn't done), the browser will prompt them to download the file.
So no browsers currently have the code necessary to render Word Documents, and as far as I know, there are no client-side libraries that currently exist for rendering them either.
you can use Google Documents' Viewer via an
<iframesrc="http://docs.google.com/gview?url=http://remote.url.tld/path/to/document.doc&embedded=true"></iframe>
You can check solution at SO link
IN case if you wants to open file using download script then you can use the
Content-type: application/vnd.ms-word
<?php
header('Content-type: application/vnd.ms-word');
header('Content-Disposition: attachment; filename="document.doc"');
readfile('path-to-file.docx');
?>
You can use the office live apps viewer , internet connection is required: //view.officeapps.live.com/op/embed.aspx?src=your_url_here
put this url in an iframe
<iframesrc='https://view.officeapps.live.com/op/embed.aspx?src=http://remote.url.tld/path/to/document.doc'width='1366px'height='623px'frameborder='0'>This is an embedded <atarget='_blank'href='http://office.com'>Microsoft Office</a> document, powered by <atarget='_blank'href='http://office.com/webapps'>Office Online</a>.</iframe>
If you only wants to display the content then you can convert word file to pdf file type. You can use cloud convert to convert files from one format to another. Currently cloud convert supports upto 128 different file formats.
There is another SO link for file format conversion
Solution 2:
The $path
has to be a full external path so that google docs can access it. You cant use a relative path like you are for this. The document will have to be internet facing to use this code.
Post a Comment for "How To Display Word Document In Browser In Localhost?"