how to write a logo on to word document using php?

Hello All,

i have created a word document using this code.. its working fine and getting all the data i needed.. i wolud like to add my website logo at the top of this document.


<?php
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=Activty_details.doc");
$table = 'events';
//$db_link = mysql_connect("localhost", "root", "root");
//mysql_select_db("vishnu",$db_link);
//$query = "SELECT * FROM $table";

//$result = mysql_query($query,$conn);

/*for ($i = 0; $i < mysql_num_rows($result); $i++) {
    $dataArray[$i] = mysql_fetch_assoc($result);
}*/
$db_link = mysql_connect("localhost", "root", "root", "vishnu");
mysql_select_db("vishnu", $db_link);


$query = "SELECT  title, event_date, event_description FROM events";
$result = mysql_query($query,$db_link) or die('cannot get results!');

/*while($row = mysql_fetch_assoc($result)) {
      $events[$row['event_date']][] = $row;

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

echo "<hr>";
echo "<h2><center> Activity Details </center></h2>";
echo "<hr>";
echo " ";
echo "<h3><center> User Name </center></h3>";
echo "<hr>";
echo " ";
//foreach ($dataArray[1] as $line) {
while($row = mysql_fetch_assoc($result)){
//echo"<b>$row[title]</b>";
echo " ";
echo "Event Title : <b> $row[title]</b>  <br/>";
echo " ";
echo "Event Start Date : <b> $row[event_date]</b>  <br/>";
echo " ";
echo "Event End Date : <b> $row[event_date]</b>  <br/>";
echo " ";
echo "Event Description: <b> $row[event_description]</b>  <br/>";
echo " ";
echo "<hr>";
//echo "<b> My first document </b>";
}
echo "</body>";
echo "</html>";

//echo $quey;
?>
vishnu kalakotaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mark BradyPrincipal Data EngineerCommented:
Wow your code needs some major reformatting. It is very hard to read. Ok aside from that, all you need to do is add another "echo" statement where you want to add your logo.

If you wanted it at the very top you could do something like this right after echo "<body>";

echo '<img src="images/your_logo.jpg" />';

Open in new window


Just change the src value to point to the location of your image. You might want to wrap it in paragraph tags <p></p>
0
vishnu kalakotaAuthor Commented:
thank you,

i have already tried this..its not working.
0
Mark BradyPrincipal Data EngineerCommented:
Ok I just tried it with a real image and it worked. Remember that when you run your php file the browser will save it in the downloads folder. It you open the doc file from there you will need to have your logo in the same folder as the doc file or it won't work.

Here is a quick example. I put a small image in the downloads folder then ran the following code. It saved the doc file and I clicked on it, and the logo was right there at the top with the content beneath it so I know this works.

<?php
    header("Content-type: application/vnd.ms-word");
    header("Content-Disposition: attachment;Filename=Activty_details.doc");
    $logo = '<img src="small-wings.png" />';
    $str = <<<DEMO
    <html>
        <head>
            <title>Test Page</title>
        </head>
        <body>
            <p>$logo</p>
            <p>Here is some <strong>content</strong></p>
        </body>
    </html>
DEMO;
 
   echo $str;
?>

Open in new window

0
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

vishnu kalakotaAuthor Commented:
thanks alot its  working.. i have got few questions
$str = <<<DEMO
DEMO;
what they mean exactly..
sorry am learner in php.

thank you.
0
Mark BradyPrincipal Data EngineerCommented:
Hi
That is a HEREDOC syntax. It allows you to mix both php and regular markup or plain text. Look it up on google. It is very helpful sometimes. I'm glad it is working now!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vishnu kalakotaAuthor Commented:
Really Good
0
vishnu kalakotaAuthor Commented:
hi Mark,
 
when i used the code to download word document with logo on my website. iys not showing logo on document.

i was ok on my local computer.. but not working on server?

any suggestions on this how to get the logo?

thank u
vishnu
0
Mark BradyPrincipal Data EngineerCommented:
Hi Vishnu. The image in the word document is a link to your image file. Make sure the image is uploaded to your website and in the same folder as the word doc. Give that a try
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.