[英]How to open file stored in stoarge folder in laravel?
I am trying to open files which is stored in "storage/app/public/cca_license/pdf_upload" folder.我正在尝试打开存储在“storage/app/public/cca_license/pdf_upload”文件夹中的文件。 When I try to open the file, the content is empty.
当我尝试打开文件时,内容为空。
What I have tried is我试过的是
account.blade.php account.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 class="fa fa-remove"></i> </a></td>
</tr>
@endforeach
@else
<tr><td colspan="4">No Pdf Listings</td></tr>
@endif
</tbody>
</table>
web.php web.php
Route::get('/openPdf/{name}', 'HomeController@openPdf');
HomeController.php HomeController.php
public function openPdf($name) {公共 function openPdf($name) {
$contents=asset('cca_license/pdf_upload/'. $name);
}
When I try to open a file, i got blank white page without file contents.当我尝试打开文件时,我得到没有文件内容的空白页。
How to view contents along with file in browser.如何在浏览器中查看内容和文件。
Your code does not contain any return statement.您的代码不包含任何返回语句。 Laravel offers a variety of ways to make responses.
Laravel 提供了多种响应方式。
https://laravel.com/docs/8.x/responses https://laravel.com/docs/8.x/responses
For example, a file response.例如,文件响应。
public function openPdf($name)
{
return response()->file(storage_path('app/public/cca_license/pdf_upload/'. $name));
}
The asset()
helper returns a URL. assets
asset()
助手返回一个 URL。 If the file is stored locally, you should refer to a local path.如果文件存储在本地,则应引用本地路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.