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
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
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
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
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
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
Share on other sites

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.