我是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