关于文件流的获取
遇到的问题:
①在做阿里云图片上传时 一个图片流无法上传(流文件捕获不到)
②在基于swoole的soft框架中导出 word 或者excel输出时直接将文件流输出到服务器了 并没有被浏览器解析
解决的办法:
①
$writer = \PHPWord_IOFactory::createWriter($phpword, 'Word2007'); ob_start(); $writer->save("php://output"); $content = ob_get_contents(); ob_end_clean(); return RequestContext::getResponse() ->withoutHeader('Content-Encoding') ->withHeader('Content-Type','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=utf-8') ->withHeader('Content-Disposition','attachment;filename="提车授权委托书.docx"') ->withBody(new SwooleStream($content));
②
$writer = \PHPWord_IOFactory::createWriter($phpword, 'Word2007'); $writer->save('提车授权委托书.docx'); $fileName = BASE_PATH . "/提车授权委托书.docx"; $file = fopen($fileName,"rb"); return RequestContext::getResponse() ->withHeader('Content-Type', 'application/octet-stream') ->withHeader('Content-Disposition', "attachment; filename=提车授权委托书.docx") ->withBody(new SwooleStream(fread($file,filesize($fileName))));
这是两种获取流文件的方法 在swoft中的应用
写的比较菜,希望可以不要介意