如何使用php生成文档文件
我有一个PHP文件,它有一个名为如何使用php生成文档文件,php,doc,Php,Doc,我有一个PHP文件,它有一个名为$data的变量。现在我在页面上回显这个变量。它工作正常,但我想将此变量写入doc文件。你是怎么做到的 我正在使用以下方法生成文档,但它不起作用 $fh = fopen('viewAppraisalDetailDoc.doc',"w+"); fwrite($fh, $data); $file = 'viewAppraisalDetailDoc.doc'; if (file_exists($file)) { header('Content-Descrip
$data
的变量。现在我在页面上回显这个变量。它工作正常,但我想将此变量写入doc文件。你是怎么做到的
我正在使用以下方法生成文档,但它不起作用
$fh = fopen('viewAppraisalDetailDoc.doc',"w+");
fwrite($fh, $data);
$file = 'viewAppraisalDetailDoc.doc';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/msword');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
我不确定它是否有效,因为我没有尝试过
浏览php COM手册,
我不确定它是否有效,因为我没有尝试过
浏览php COM手册,
这个主意很糟糕,因为它是一个仅限windows的扩展。通常所有服务器都在unix或linux上。那么它是如何有用呢?这是一个非常糟糕的主意,因为它是一个仅限windows的扩展。通常所有的服务器都在unix或linux上。那么它有什么用处呢??
<?php
// starting word
$word = new COM("word.application") or die("Unable to instantiate Word");
echo "Loaded Word, version {$word->Version}\n";
//bring it to front
$word->Visible = 1;
//open an empty document
$word->Documents->Add();
//do some weird stuff
$word->Selection->TypeText("This is a test...");
$word->Documents[1]->SaveAs("Useless test.doc");
//closing word
$word->Quit();
//free the object
$word = null;
?>