phpdocx - generating word documents via phpdocx library

893 views Asked by At

I am in need of making files dynamically in editable word form from php and mysql. I found good library PHPdocx and it works for now, but it saves output file to the server. All I want to open word document file from web serwer on my browser window. First I tried:

header("Location: example_text.docx");

Unfortunatelly it doesnt work because it is still opened in php file instead of docx. Then I found a better way:

echo "
<script>
    window.location.replace('example_text.docx')
</script>
";

It works fine but still doesnt satisfy me - It opens a standard browser window with a question - open or save file to local hard disk. I want to automatically see generated file, and than decide if i want to save it to local hard drive. Is there a way to do this? I guess it is matter of browser preferences but not sure. Please advice.

1

There are 1 answers

0
Shankar Narayana Damodaran On

You can achieve this using COM , but it is not browser-compliant. However try this way.

header('Content-disposition: inline');
header('Content-type: application/msword');
readfile('yourwordfile.doc');
exit;