你能告訴我我的頭文件有什麼問題嗎?我的下載無效。我用PHPWord庫,但我不認爲這是一個問題無法下載word文件
<?php
require_once 'PHPWord.php';
$PHPWord = new PHPWord();
$section = $PHPWord->createSection();
$wordText = utf8_encode($_REQUEST['TEXT']);
$section->addText($wordText);
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
//$objWriter->save('helloWorld.docx');
$path = 'tmp/kikou2.docx';
$objWriter->save($path);
//download code
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' .$path);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Content-Length: ' . filesize($objWriter));
readfile($objWriter);
unlink($objWriter); // deletes the temporary file
exit;
?>
感謝
它不起作用(其他人的回答也不太...),你有什麼想法嗎? – So4ne
我不好使用POST ajax請求,它不允許我調用該文件。但你的回答很好,很有幫助,謝謝! – So4ne