How to create a word document from PHP form input and save it in a file

I have a form page

index.php

<form name="proposal_form" action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post">
  <table cellpadding="0" cellspacing="0" border="0" width="100%"> 
          <tr> 
            <td width="23%" class="body"> Name</td> 
            <td width="3%" class="body">:</td> 
            <td width="74%"><input type="text" name="strname" class="textfield"></td> 
        </tr> 


      </table>    
  <input type="submit" name="submit_docs" value="Export as MS Word" class="input-button" />
</form>

<?php


  if(isset($_POST['submit_docs'])){
 $doc_body ='
 <table cellpadding="0" cellspacing="0" border="0" width="100%"> 
          <tr> 
            <td width="23%" class="body"> Name</td> 
            <td width="3%" class="body">:</td> 
            <td width="74%">'.$_POST["strname"].'</td> 
        </tr> 

      </table>    
 ';}

  header("Content-Type: application/vnd.msword");
  header("Expires: 0");//no-cache
  header("Cache-Control: must-revalidate, post-check=0, pre-check=0");//no-cache
 header("content-disposition: attachment;filename=sampleword.doc"); 
 //store in local file
file_put_contents( "/files/sample.doc",$doc_body);
 ?>

I am trying to create a word file when the form is submitted But its not showing in the Folder.

Any idea where I am doing mistake

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s