Home arrow PHP arrow Page 3 - PHP: Creating Word Documents without .COM Objects

The Basic Web Form Source Code - PHP

If you are looking for a solution to create MS Word documents without the use of .COM objects, then this tutorial will be helpful. In it, you will learn how to build an actual PHP application that can convert a .txt file into a .doc file online.

  1. PHP: Creating Word Documents without .COM Objects
  2. Strategy for creating this application
  3. The Basic Web Form Source Code
  4. PHP Script: Validation, File get Contents and Writing to .doc file
  5. Deleting Temporary Files in the Server Upload directory
By: Codex-M
Rating: starstarstarstarstar / 5
July 26, 2010

print this article



Based on the flowchart, the first major steps are presentation of the web form and recaptcha. Below is the source code for this section:



<TITLE>Convert Text File (.txt) to MS Word (.doc) using PHP</TITLE>



<font face="Courier" size="2">



<H2>Convert Text File to MS Word</H2>


<b>Background</b>: This will convert your text file (.txt extension) into an MS Word file (.doc extension).The converted version is compatible for MS Word 2002 but it may also work with newer versions of MS Word.

<br /><br />

Bear in mind that files are deleted every 3 to 10 minutes so you need to download the converted file right away.

<br /><br />

Note that after downloading and opening the file, you might encounter these two common errors:

<br />

1. MSWRD632 related errors. In this case, you need to read this solution: <font color="blue">http://social.answers.microsoft.com/Forums/en-US/wordcreate/thread/ce3a65ce-fba1-4c16-af9c-d4131a281527</font>

<br />

2.) Now if another error appears like asking you install a text converter or like that just click "Yes" to proceed to any installation. This will let you open the converted files without any error the next time around.

<br />

<br /><br />

Maximum allowable Text File upload size: <b>100kB</b>

<br /><br />

<!-- Input form begin -->

<form NAME="texttoword" ACTION="<? echo $PHP_SELF; ?>" method="post" enctype="multipart/form-data">

<label for="file">Filename:</label>

<br /><br />

<input type="file" name="file" id="file" />

<INPUT TYPE="HIDDEN" NAME="ref" VALUE="texttoword">

<br /><br />

Type the captcha below:

<br /> <br />



$publickey = "***PUT YOUR OWN PUBLIC KEY HERE***";

echo recaptcha_get_html($publickey);


<br /> <br />

<INPUT CLASS="DEFAULT" TYPE=SUBMIT VALUE="Convert this text file to MS Word">


<br />

<br />

The code looks self-explanatory. It includes user-friendly information that will be useful if the client encounters a problem when opening the converted MS Word file.

Also, the recaptcha code snippet should be placed above the submit button and the </form> tag.

The form should look like the screen shot below:

>>> More PHP Articles          >>> More By Codex-M

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: