Embedding an image in document using php – PHP



// starting word
$text = "My Text";
//Start MS Word
$Word = new COM("word.application") or die("Failure: Word did not start");
echo("WORD has started.");
//Formating the Font
$Word->Selection->Font->Name = "Arial";
$Word->Selection->Font->Size = 12;
$Word->Selection->Font->ColorIndex = 4;
//Add text to the document
//Insert Image
//Save document

I have tried the abouve code for embedding an image in document using php.But i am getting an error
WORD has started.

Fatal error: Uncaught exception ‘com_exception’ with message ‘<b>Source:</b> Microsoft Word<br/><b>Description:</b> This is not a valid file name. Try one or more of the following: * Check the path to make sure it was typed correctly. * Select a file from the list of files and folders.’ in F:\Projects\fida\word.php:20
Stack trace:
#0 F:\Projects\fida\word.php(20): variant->AddPicture(‘f:\Projects?ida…’)
#1 {main} thrown in F:\Projects\fida\word.php on line 20

Please help to get rid of these


backslashes are the general escape character in PHP. either you use single quotation marks (unparsed string) or you escape the backslashes (with backslashes).

\f – form feed character


Thanks for your help!it worked


Is there any function to set up header and footer in a word document using php


not that I’m aware of, seems rather unlikely (most servers do not run windows)


i have searched through so many documents ,but not found nay way to set header and footer for a word document using php while i create the document using COM functions.Its very urgent for me


I can’t help you much there, never used COM objects before. Judging from the manual I’d say you need the Word OLE Interface (because that what’s COM working with) to find header/footer functionality.