简体   繁体   English

如何打开存储在 laravel 的 stoarge 文件夹中的文件?

[英]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.

相关问题 Laravel 5.7:pdf文件存储在文件夹中 - Laravel 5.7: pdf file gets stored in folder 我们如何读取laravel的views文件夹中存储的html文件的内容? - How can we read the content of html file which is stored in views folder in laravel? 如何读取存储在 Laravel 的 Config 文件夹中的数据文件中保存的数组值 - How can I read an array value saved in a data file stored inside Config folder in Laravel 如何根据 Laravel 中的文件类型为存储文件夹中存储的图像、pdf 等文件提供下载选项? - How to give download option for image,pdf etc files stored in storage folder depending on type of file in Laravel? Laravel-通过超链接打开存储在App目录中的文件吗? - Laravel - Open file stored in App directory through hyperlink? 如何调用存储在不同文件夹和文件中的函数? - How call a function that is stored on a different folder and file? 图像未存储在Laravel的文件夹中 - Images are not being stored in folder in Laravel Laravel不会打开公用文件夹中具有特定名称的文件 - Laravel doesn't open a file with a specific name from the public folder 如何使用Filesystem访问Laravel中存储的文件? - How to access stored file in Laravel with Filesystem? 如何检索存储在laravel5.4的存储文件夹中的图像? - How to retrieve the images stored in storage folder of laravel5.4?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM