我是laravel中的新成员,我使用phpword来编辑word doc文件。laravel 5.4,phpword:如何在不强制下载的情况下显示带有只读权限的word文档?
我想要一次保存它我可以在中显示它只读权限。
我想直接显示它而不强制下载。
我试过这段代码,但它强制下载。
这里是我的代码:
public function create()
{
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
//Ajouter l'image
$section->addImage(
'C:\wamp\www\Stage_2\public\images\mobilis256.png',
array(
'width' => 100,
'height' => 100,
'marginTop' => -1,
'marginLeft' => -1,
'wrappingStyle' => 'behind'
));
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
try {
$objWriter->save(storage_path('helloWorld.docx'));
}catch(Exception $e)
{}
$filename = 'helloWorld.docx';
$path = storage_path($filename);
return Response::make(file_get_contents($path), 200, [
'Content-Type' => 'application/docx',
'Content-Disposition' => 'inline; filename="'.$filename.'"'
]);
}
我也尝试
return response()->file(storage_path('helloWorld.docx'));
但总是相同的结果。
我该怎么办,我该如何显示它在只读权限?
您不能在浏览器中显示文档,除非他们有某种插件来处理该文档。 – Samsquanch
那么解决方案是什么? –
以另一种方式做。 PDF或其他东西。 – Samsquanch