gpt4 book ai didi

PHP 在生成文档时在服务器上创建文档副本

转载 作者:可可西里 更新时间:2023-11-01 08:06:32 25 4
gpt4 key购买 nike

在我的应用中,用户可以根据租赁元素创建收据。

我使用此代码从现有模板创建一个 Word 文件 (.doc)。

        header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=Rent_Receipt_". $_SESSION['custid'] .".doc");
include ("templates/template_receipt.php");

现在用户将把它存储在他的本地计算机上,但是我怎样才能让服务器将这个相同的文档存储在服务器文件夹中,这样用户就不必手动上传了?

提前致谢。

编辑
include: template_receipt.php 包含要创建的 Word 文档的 HTML 代码:

<?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*_。感谢您的快速回复。

最佳答案

ob_* 函数会有所帮助。
例如:

<?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 在生成文档时在服务器上创建文档副本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13701029/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com