Jump to content

image in doc file


kituscat

Recommended Posts

Hi eveybody,

 

i'm generating a doc file from php usu

 


<?php
$vExcelFileName="export". ".doc";
header("Content-type: application/x-ms-download"); //#-- build header to download the excel file 
header("Content-Disposition: attachment; filename=$vExcelFileName"); 
header('Cache-Control: public'); 
?>


 

on the top of my php file.

 

Does anyone know how can i generate the doc files with images on it?

 

Thanx!

 

Marc

Link to comment
https://forums.phpfreaks.com/topic/146252-image-in-doc-file/
Share on other sites

i'm generating a doc file from php

A .doc file or an Excel file? Your example code is a set of headers that suggest Excel rather than MS Word.

 

What library or tools are you using to actually generate the file?

 

Incidentally, the MIME content type for Excel is:

application/vnd.ms-excel for .xls files

application/vnd.openxmlformats-officedocument.spreadsheetml.sheet for xlsx files

 

the MIME content type for Word is:

application/msword for .doc files

application/vnd.openxmlformats-officedocument.wordprocessingml.document for docx files

 

Link to comment
https://forums.phpfreaks.com/topic/146252-image-in-doc-file/#findComment-767961
Share on other sites

Hi Mark,

 

... i don't know what library or tool i'm using  ... in fact, i was searching code to generate doc files from php to create bills and i found this code. I swear it generates a doc file :) But i don't know if it's correct or if i should use any other better .... any help would be usefull!!

 

thanx

Link to comment
https://forums.phpfreaks.com/topic/146252-image-in-doc-file/#findComment-768357
Share on other sites

i'm not expecting .... it does generate a doc file only with that code.

I doubt that very much.

 

Your output might create a file with an extension of .doc, even one that MS Word can read because it's simply going to be plain text.... but unless you're using some form of library that is capable of generating an MS Word file then it isn't a doc file.

If you don't believe me, then try opening a real Word document file in a text editor like notepad to see what it looks like, then try opening the files that you're generating in notepad and see how different they look.

 

Unless we know how you're creating a Word file, we can do very little to help... from your description, you aren't generating a Word file.... just a simple text file or an HTML file.

 

 

A file containing the following:

Hello World<br />

<img width="31" height="30" src="http://www.w3schools.com/images/compatible_ie.gif" />

<table border=1>
<tr><td>Cell A1</td><td>Cell B1</td></tr>
<tr><td>Cell A2</td><td>Cell B2</td></tr>
</table>

<i>This</i> is <b>NOT</b> a Word file

will open in MS Word.... but it's an HTML file, not a Word document.

 

Note that the image will display because I'm using a full URL; but it will only display when you're connected to the Internet while viewing the file.

 

Link to comment
https://forums.phpfreaks.com/topic/146252-image-in-doc-file/#findComment-768679
Share on other sites

If your web server is a Windows server, and has Word installed, you can use PHP's .COM module to create MS Word documents.

 

Alternatively (and these are just a couple of example tools)

http://paggard.com/projects/rtf.generator/

http://www.phpclasses.org/browse/package/1805.html

 

Link to comment
https://forums.phpfreaks.com/topic/146252-image-in-doc-file/#findComment-769481
Share on other sites

Thanks for your help Mark. I'll try these.

 

What do you think about this code i found?

 



<? 
$nombre = 'documento.doc'; 
$contenido = '{\rtf1{\fonttbl{\f0 Arial;}} 
\f0\fs20 El parámetro pasado es: \b '.$_GET["parametro"].' \b0\par 
Documento generado el \b '.date("j \d\e\l n \d\e Y").' \b0\par 
}'; 
header( "Content-Type: application/octet-stream"); 
header( "Content-Disposition: attachment; filename=".$nombre.""); 
print($contenido); 
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/146252-image-in-doc-file/#findComment-772892
Share on other sites

Honest answer.... I think it's a very long-winded way of generating a document, but RTF should let you embed images, and MS Word works well with RTF files.

The better solution is still to use a library; which means you don't need to understand the structure of the file itself, or worry about forgetting a closing } when you define the content of the file.

Link to comment
https://forums.phpfreaks.com/topic/146252-image-in-doc-file/#findComment-773186
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.