PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
popper
Forum Newbie
Posts: 3 Joined: Thu Nov 18, 2004 2:51 am
Post
by popper » Thu Nov 18, 2004 3:02 am
Hello everybody
how can i generate ms doc files using php? (version doesnt matter)
i 've tried the following code:
Code: Select all
header("Content-type: application/msword");
header('Content-Disposition: attachment; filename="my.doc";');
echo "Helloooooooooooooooooo";
But it doesn't work. Do i have to change something particular in apache/php.ini config files?
i search the site but i find only parser to generate html from doc file, i need the opposite procedure.
thanks all,
bye
Davide
phpScott
DevNet Resident
Posts: 1206 Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.
Post
by phpScott » Thu Nov 18, 2004 3:09 am
search the forum for ms word.
I've done it for you
viewtopic.php?t=27003
It has a link to where you can read about php and creating word documents.
phpScott
popper
Forum Newbie
Posts: 3 Joined: Thu Nov 18, 2004 2:51 am
Post
by popper » Thu Nov 18, 2004 4:21 am
10x man, i've searched only in the site
.
now it work, i've used this code
Code: Select all
?php
// Word execution
$word = new COM("word.application") or die("Non sono riuscito ad eseguire Word");
$word->Visible = 1;
//open empty doc
$word->Documents->Add();
//text operations
$word->Selection->TypeText("formattazione lettera blalblallb\n\n nome cliente " . $_POSTїtesto]);
$word->Documentsї1]->SaveAs("e:\webroot\ciao.doc");
//close Word
$word->Quit();
//send to browser
$word->Release();
$word = null;
header("Content-type: application/msword");
header('Content-Disposition: attachment; filename="ciao.doc"');
readfile("ciao.doc");
?>
this script create a doc file, using the text passed by a post form.
Then it send the file to the browser for downloading/opening.
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Thu Nov 18, 2004 5:02 am
What happens if this script is executed by more than one person at the same time?
a possible scenario
person1: write document e:\foo.doc
person2:write document e:\foo.doc
person1: recieve e:\foo.doc
<-- concurrency problem! save the documents using a unique filename
popper
Forum Newbie
Posts: 3 Joined: Thu Nov 18, 2004 2:51 am
Post
by popper » Thu Nov 18, 2004 8:35 am
this is a test code, only to try if ms doc generation works. In "final version" ill'put some synchronization, doc's file name probably will be determinated by unique mysql's table key.