HomePHP Page 2 - PHP: Creating Word Documents without .COM Objects
Strategy for creating this application - 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.
Since this application does not use .com objects, an alternative solution focuses mainly on the fopen PHP function. Below is the flowchart of this application:
Suppose you are going to use PHP to convert a .txt file to .doc. It starts by checking to see if the web form has been submitted. If the web form has been submitted, PHP will validate the recaptcha, file type (file uploaded should be of the .txt file type) and file size (for example, if it is less than the 100 KB upload limit).
If there are no errors in this validation, PHP will simply get the content from the uploaded text file, which is placed in the temporary upload directory of the server. If the file is not created, fopen will create the .doc file.
Once the file has been created, PHP will write the contents to an MS Word file using the fwrite command, and finally, present the download link to the client.
To manage the size of the upload directory, and for maintenance, an external PHP script will be regularly executed using web hosting cron tab (http://adminschoice.com/crontab-quick-reference) features. The objective of the script is to check for files in the directory (with the .txt and .doc extensions) which were created more than three minutes ago in the directory. If the files were created more than three minutes ago, those files will be scheduled for deletion by the cron job.
This feature is added to prevent temporary files from clogging the server's temporary upload directory, to save some disk space.
The entire process looks simple, and this tutorial will guide you through all of these steps in detail.