我想在readfile()完成后取消链接文件
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');
$name = microtime();
$path = 'tmp/Services.docx';
$objWriter->save($path);
$essai = 'php/'.$path;
echo $essai;
readfile($objWriter);
unlink($path);
exit;
关键是文件在读取之前已取消链接!我的意思是,当我启动下载时,我有一个漂亮的 404 not found 。如果我删除unlink,我的下载工作正常
这是我在javascript方面所做的,它是ExtJs:
Ext.Ajax.request({
url: 'php/treeWord.php',
method: 'POST',
params: {
'TEXT' : arrString
},
success : function(r){
var javaScriptVar = r.responseText;
alert (javaScriptVar);
window.open(javaScriptVar);
}
});