kituscat Posted February 21, 2009 Share Posted February 21, 2009 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 More sharing options...
Mark Baker Posted February 21, 2009 Share Posted February 21, 2009 i'm generating a doc file from phpA .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 More sharing options...
kituscat Posted February 22, 2009 Author Share Posted February 22, 2009 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 More sharing options...
Mark Baker Posted February 22, 2009 Share Posted February 22, 2009 The code that you've posted does very little of anything besides trying to set the http response headers, and does even that totally incorrectly for either a .doc or for an .xls file. How are you generating the actual .doc file? Link to comment https://forums.phpfreaks.com/topic/146252-image-in-doc-file/#findComment-768374 Share on other sites More sharing options...
kituscat Posted February 22, 2009 Author Share Posted February 22, 2009 after that code i only have some queries to a database to extract information. Whem i call the page it generates a doc file with the information .... Link to comment https://forums.phpfreaks.com/topic/146252-image-in-doc-file/#findComment-768443 Share on other sites More sharing options...
Mark Baker Posted February 22, 2009 Share Posted February 22, 2009 Whem i call the page it generates a doc file with the information ....So you're simply echoing the data from your database, and expecting it to generate an excel workbook or a word document? Link to comment https://forums.phpfreaks.com/topic/146252-image-in-doc-file/#findComment-768598 Share on other sites More sharing options...
kituscat Posted February 22, 2009 Author Share Posted February 22, 2009 i'm not expecting .... it does generate a doc file only with that code. Link to comment https://forums.phpfreaks.com/topic/146252-image-in-doc-file/#findComment-768662 Share on other sites More sharing options...
Mark Baker Posted February 22, 2009 Share Posted February 22, 2009 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 More sharing options...
kituscat Posted February 23, 2009 Author Share Posted February 23, 2009 ok ... I understand .....sorry, but i'm trying to learn .... So what should i do to creat a real doc or rtf file? Link to comment https://forums.phpfreaks.com/topic/146252-image-in-doc-file/#findComment-769445 Share on other sites More sharing options...
Mark Baker Posted February 23, 2009 Share Posted February 23, 2009 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 More sharing options...
Mark Baker Posted February 24, 2009 Share Posted February 24, 2009 Another tool that supposedly allows you to read/write Word documents http://www.phplivedocx.org/ Link to comment https://forums.phpfreaks.com/topic/146252-image-in-doc-file/#findComment-770078 Share on other sites More sharing options...
kituscat Posted February 27, 2009 Author Share Posted February 27, 2009 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 More sharing options...
Mark Baker Posted February 28, 2009 Share Posted February 28, 2009 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.