我正在嘗試打開存盤在“storage/app/public/cca_license/pdf_upload”檔案夾中的檔案。當我嘗試打開檔案時,內容為空。
我試過的是
賬戶.blade.php
<table id="table" class="table table-bordered text-center">
<thead>
<tr>
<th>PDF Name </th>
<th>Date</th>
<th>View</th><!-- comment -->
<th>Delete</th>
</tr>
</thead>
<tbody>
@if(count($pdf_data)> 0)
@foreach($pdf_data as $data)
<tr>
<td>{{$data->pdf_name}}</td>
<td>{{$data->pdf_date}}</td>
<td>
<a href="/openPdf/{{$data->pdf_name}}"><i class="fa fa-eye"></i></a>
<!-- <iframe id="ifrm" src="/cca_license/pdf_upload/txtfile-converted_1640170538.pdf" >
</iframe>-->
</td>
<td><a href="/deleteFile/{{$data->id}}"><i hljs-string">"></i> </a></td>
</tr>
@endforeach
@else
<tr><td colspan="4">No Pdf Listings</td></tr>
@endif
</tbody>
</table>
網頁.php
Route::get('/openPdf/{name}', 'HomeController@openPdf');
家庭控制器.php
公共函式 openPdf($name) {
$contents=asset('cca_license/pdf_upload/'. $name);
}
當我嘗試打開一個檔案時,我得到了沒有檔案內容的空白頁面。

如何在瀏覽器中查看內容和檔案。
uj5u.com熱心網友回復:
您的代碼不包含任何 return 陳述句。Laravel 提供了多種回應方式。
https://laravel.com/docs/8.x/responses
例如,檔案回應。
public function openPdf($name)
{
return response()->file(storage_path('app/public/cca_license/pdf_upload/'. $name));
}
該asset()助手回傳一個URL。如果檔案存盤在本地,則應參考本地路徑。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/391972.html
上一篇:如何在注冊表中上傳和保存影像?
