[英]How to create a word document from PHP form input and save it in a file
I have a form page 我有一个表单页面
index.php 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. 我正在尝试在提交表单时创建一个word文件,但是该文件未显示在Folder中。
Any idea where I am doing mistake 知道我在哪里做错
Try this in PHP to save as a Word document. 在PHP中尝试将其另存为Word文档。 Just use your values instead of the examples I have put in them.
只需使用您的值而不是我在其中输入的示例即可。
<?php
$value1 = $_POST['Name'];
$value2 = $_POST['Phone'];
$value3 = $_POST['State1'];
$value4 = $_POST['MemberID'];
$value5 = $_POST['TaxID'];
$value6 = $_POST['UserID'];
$value7 = $_POST['Facility'];
$value8 = $_POST['Email'];
$value9 = $_POST['AdditionalNotes'];
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=PSSD.doc");
echo "<html>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">";
echo "<body>";
echo "<b><i>Name:</i> ".$value1."</b> \t \t \n <br>";
echo "<b><i>Phone#:</i> ".$value2."</b> \t \t \n <br>";
echo "<b><i>State:</i> ".$value3."</b> \t \t \n <br>";
echo "<b><i>Member ID:</i>".$value4."</b> \t \t \n <br>";
echo "<b><i>Tax ID: </i>".$value5."</b> \t \t \n <br>";
echo "<b><i>User ID:</i> ".$value6."</b> \t \t \n <br>";
echo "<b><i>Facility: </i>".$value7."</b> \t \t \n <br>";`enter code here`
echo "<b><i>Email: </i>".$value8."</b> \t \t \n <br>";
echo "<b><i>Additional Notes: </i>".$value9."</b> \t \t \n <br>";
echo "</body>";
echo "</html>";
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.