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?
 
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
 
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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
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
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.