Home arrow PHP arrow 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.

TABLE OF CONTENTS:
  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
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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.



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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- 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: