Jump to content

Recommended Posts

Hi,

 

Well I have been working on Php for quite sometime but creating Word Docs is something I am totally new to. I googled about this and found different methods of creating word documents via php. The most promising one that I found involves writing HTML code and inside header, save it as a *.doc file (I know thats not exactly a Word File but what else can be done). Like this,

 

header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment; Filename=Report.doc");

 

The whole word document came out perfectly fine, but there was one little problem (later on turned out to be the BIGGEST one) was placing images in the document. All the images were saved on a secure server so like we do in HTML, I used the following line of code,

 

<img src="https://somewebaddress/users.png" />

 

The word document appeared to be fine for me, but when that document was sent to the client, client was unable to view the images. Now, I guess you all know what my question would be, and that is, is there a way we could somehow make this work. I even tried downloading all the images to disk and giving their path, still in the end, the document only needs to be sent to the client and images do not appear.

 

Please help me in this regards, Thanks in advance to all :)

 

P.S. Please see the following sample (mini) code of the real thing, real document is a bit toooooooo big and kind of confidential  :confused:

 

<?php
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment; Filename=Report.doc");
?>

<html>
<head>
<title>TCS Monthly Report $month $year</title>
</head>
<body>

<b><h3>    Monthly Operational User Statistics</h3></b>
<br>

    The red line is users logged in over the month. The green area is users recently logged in (last few days).<br>

    <br><img src="https://somewebaddress/users.png" />

</body>
</html>

Hi cooldood, Well I am using the full url not the absolute one, coz the images that needs to be in the report, are not only on one server but spread over a few servers. That is why, I decided on using full url instead of absolute one.

 

Also, Adam, can you be a little more specific about it ... Thanks :)

 

Regards,

Mubin

Read the link I sent. Once you're familiar with how it works it's just a case of converting the image to base64 (base64_encode) and outputting it within that scheme. I've never tried to actually do that within a Word document, but I can't see why it wouldn't work.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.