简体   繁体   English

我们可以访问存储文件夹文件以在 Laravel 中下载吗?

[英]Do we have access to storage folder file for download in Laravel?

I am storing some json files is storage folder,and converting all of them to pdf and storing in storge folder only.我正在存储一些 json 文件是存储文件夹,并将它们全部转换为 pdf 并仅存储在存储文件夹中。

I want to download the pdf now through ajax.我想现在通过ajax下载pdf。

Is there anyway to make the storage folder file available publicly.有没有办法让存储文件夹文件公开可用。

I won't open it for direct access, but i would suggest to use an function in your Controller like this:我不会打开它直接访问,但我建议在你的控制器中使用这样的函数:

public function getPdf() {

    $file = "XYZ/storage/download/info.pdf";
    $headers = array(
        'Content-Type: application/pdf',
    );

    return \Response::download($file, 'filename.pdf', $headers);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM