问题描述
在我的应用程序中,用户可以根据租金项目创建收据.
In my application, the user can create a receipt according to the rent items.
我使用此代码从现有模板中创建Word文件(.doc).
I use this code to create a Word file (.doc) out of an exisiting template.
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=Rent_Receipt_". $_SESSION['custid'] .".doc");
include ("templates/template_receipt.php");
现在用户会将其存储在他的本地计算机上,但是我如何使服务器将同一文档存储在服务器文件夹中,所以用户不必手动上载它?
Now the user will have this stored on his local computer, but how can I make the server to store this same document in the server folder, so the user don't have to upload it manually?
谢谢.
编辑
包括:template_receipt.php包含要创建的Word文档的HTML代码:
EDIT
The include: template_receipt.php contains HTML code for the Word document to be created:
<?php echo "
<html xmlns:v='urn:schemas-microsoft-com:vml'
xmlns:o='urn:schemas-microsoft-com:office:office'
xmlns:w='urn:schemas-microsoft-com:office:word'
xmlns:m='http://schemas.microsoft.com/office/2004/12/omml'
xmlns='http://www.w3.org/TR/REC-html40'>
<head>
<meta http-equiv=Content-Type content='text/html; charset=windows-1252'>
<meta name=ProgId content=Word.Document>
<meta name=Generator content='Microsoft Word 14'>
<meta name=Originator content='Microsoft Word 14'>
<link rel=File-List href='Template%20Verhuurbon_files/filelist.xml'>
<link rel=Edit-Time-Data href='Template%20Verhuurbon_files/editdata.mso'>
<link rel=dataStoreItem href='Template%20Verhuurbon_files/item0001.xml'
target='Template%20Verhuurbon_files/props002.xml'>
<link rel=themeData href='Template%20Verhuurbon_files/themedata.thmx'>
<link rel=colorSchemeMapping
href='Template%20Verhuurbon_files/colorschememapping.xml'>
以此类推.我将在一秒钟内查看此ob*_
.谢谢您的快速回复.
And so on. I'm going to look into this ob*_
in a second. Thank you for fast response.
推荐答案
ob_*
函数将有所帮助.
例如:
ob_*
functions will help.
For example:
<?php
// geting file content
ob_start();
include ("templates/template_receipt.php");
$content = ob_get_contents();
ob_end_clean();
//store in local file
file_put_contents('/file/name.txt',$content);
// file output:
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=Rent_Receipt_". $_SESSION['custid'] .".doc");
echo $content;
?>
这篇关于PHP在生成文档时在服务器上创建文档副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!