1

I'm having problems with exporting the picture to word file.

I have written the php script which fetches the content of two columns of my mysql database and then export those contents in the word file. One of the columns is for images.

The script is running fine but i am having problems with fetching the image to the word file. Its not displaying images.

I need to know the way to fetch that image to the word file.

<?php
include('config.php');
$silver_events=mysql_query("select * FROM tb_property Where property_id='34'; ");
$silver_events_row=mysql_fetch_array($silver_events);

$sample_text = $silver_events_row['property_name'];
$sample_text1 = $silver_events_row['property_image0'];

$word_xmlns = "xmlns:o='urn:schemas-microsoft-com:office:office' 
xmlns:w='urn:schemas-microsoft-com:office:word' 
 xmlns='http://www.w3.org/TR/REC-html40′";

 $word_xml_settings = " <xml><w:WordDocument>
      <w:View>Print</w:View><w:Zoom>100</w:Zoom>    
      </w:WordDocument></xml>";

   $word_landscape_style = "@page {size:8.5in 11.0in; margin:0.5in 0.31in 
        0.42in 0.25in;} div.Section1{page:Section1;}";

   $word_landscape_div_start = "<div class='Section1′>";
   $word_landscape_img='<img src="../user_image/ACN NAIR.jpg" />';
   $word_landscape_div_end = "</div>";

   $content = '<html '.$word_xmlns.'>
        <head>
    <title>Export Data to word document</title>'  
        .$word_xml_settings.'<style type="text/css">
        '.$word_landscape_style.' table,td {border:0px solid #FFFFFF;}
          </style>
    </head>
    <body>'.$word_landscape_div_start . $sample_text . 
        $sample_text1 . $word_landscape_img . $word_landscape_div_end.'
    <img src="'.$sample_text1.'"  /></body>
</html>';

  @header('Content-Type: application/msword');
  @header('Content-Length: '.strlen($content));
  @header('Content-disposition: inline; filename="Silver Events.doc"');
  echo $content;

 ?>
Harish Singh
  • 3,359
  • 5
  • 24
  • 39
  • Do you see the correct image if you echo the output on to the screen instead of exporting it straight into word? – Ryan Dec 04 '13 at 11:36
  • @Stanyer yeah i am able to see the correct image in my page. –  Dec 04 '13 at 11:40
  • 1
    A relative URL such as `` has no meaning when it is referenced from a different computer to your server; either use an absolute URL for the image, or embed the image data as a base64 encoded stream in your markup – Mark Baker Dec 04 '13 at 11:41
  • 1
    Does this help? http://stackoverflow.com/a/3315805/1209020 – Ryan Dec 04 '13 at 11:42
  • @Mark even while giving absolute path to make this work. The image is not being displayed. –  Dec 04 '13 at 11:48

0 Answers0