douruyun8153 2014-02-26 08:57
浏览 47

读取文件后,使用unlink()删除文件

I want to unlink a file once the readfile() is finished

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;

The point is the file is unlinked before it's read ! I mean that when I launch my download I have a beautiful 404 not found. If I remove the unlink my download is working fine

Here is what I do in javascript side, it's 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);
                    }
                }); 
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#python#的问题,请各位专家解答!
    • ¥15 对于这个问题的解释说明
    • ¥200 询问:python实现大地主题正反算的程序设计,有偿
    • ¥15 smptlib使用465端口发送邮件失败
    • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
    • ¥15 对于squad数据集的基于bert模型的微调
    • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
    • ¥20 steam下载游戏占用内存
    • ¥15 CST保存项目时失败
    • ¥20 java在应用程序里获取不到扬声器设备