racebennon Posted August 24, 2011 Share Posted August 24, 2011 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 <?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> Quote Link to comment https://forums.phpfreaks.com/topic/245583-creating-word-documents-on-a-linux-server/ Share on other sites More sharing options...
cooldood Posted August 24, 2011 Share Posted August 24, 2011 Hi. Are you using a full URL, or a path on the same server containing the images? eg. http://maxamity.com/social101/images/image.jpg is a full URL. Path is something like ../images/mainimage.png Thanks! Nick. Quote Link to comment https://forums.phpfreaks.com/topic/245583-creating-word-documents-on-a-linux-server/#findComment-1261346 Share on other sites More sharing options...
Adam Posted August 24, 2011 Share Posted August 24, 2011 You could also store base64 encoded data as the src, using the Data URI Scheme. Quote Link to comment https://forums.phpfreaks.com/topic/245583-creating-word-documents-on-a-linux-server/#findComment-1261359 Share on other sites More sharing options...
racebennon Posted August 24, 2011 Author Share Posted August 24, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/245583-creating-word-documents-on-a-linux-server/#findComment-1261418 Share on other sites More sharing options...
Adam Posted August 24, 2011 Share Posted August 24, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/245583-creating-word-documents-on-a-linux-server/#findComment-1261424 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.