Download MS Word document

A place for users and developers of the Xataface to discuss and receive support.

Download MS Word document

Postby Gershy » Wed Jan 09, 2013 1:26 pm

Hey y'all, to allow the user to download ms word .doc files without COM or other libraries is very easy; this link here shows how:

http://stackoverflow.com/questions/124959/create-word-document-using-php-in-linux

(I'm using a linux server)
I've done this before and its worked fine, but I have an action in xataface that causes database info to download in an ms word document.

Here's msword_output.php:

Code: Select all
<?php
@session_start();
$lines = $_SESSION['msword_output'];

header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=doc.doc");
?>

<html><body>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">      

<?php   
foreach ($lines as $line) {
   echo $line; ?><br/><?php
}
?>

</html></body>

<?php
unset($_SESSION['msword_output']);
?>


It's very simple to use; set $_SESSION['msword_output'] to an array of the lines you wish to download as .doc, call include('msword_output.php'), and there you go.

Everything works fine except my problem is: the html is taken literally and written to the document, so instead of a line break the .doc literally says <br/>.

This method has worked for me before, so I'm nearly positive that the issue has to do with xataface's html context which msword_output.php is operating within.

Could anyone shed some light on this matter?

Thanks in advance! :)
Gershy
 
Posts: 25
Joined: Wed Nov 14, 2012 12:28 pm

Re: Download MS Word document

Postby shannah » Wed Jan 09, 2013 1:55 pm

Where is this code running? Is it a script by itself? If so it doesn't even look like Xataface comes into play here (you're not including any of Xataface in this example).
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 32 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved