简体   繁体   English

我无法显示 Laravel 中存储的文件 6

[英]I can't show a file from storage in Laravel 6

I have a Laravel 6.0 application where users can upload files to a server and it stores in the storage file system of laravel .我有一个 Laravel 6.0 应用程序,用户可以在其中将文件上传到服务器,并将其存储在laravel的存储文件系统中。 The system I'm using has been working in an older Laravel 5.6 project.我使用的系统一直在旧的 Laravel 5.6 项目中工作。

The link the Controller gives me: Controller 的链接给了我:

domainame.com/public/file?folder=foldername&file=1569323440filename.png domainame.com/public/file?folder=文件夹名&文件=1569323440filename.png

Controller Controller

public function getFile($foldername, $filename)
{
    $fullpath = "app/{$foldername}/{$filename}";

    return response()->download(storage_path($fullpath), null, [], null);
}

public function getFilesubfolder($foldername, $subfolder, $filename)
{
    $fullpath = "app/{$foldername}/{$subfolder}/{$filename}";

    return response()->download(storage_path($fullpath), null, [], null);
}

View看法

{{ route('file.show' ,['folder' => 'empresas' , 'file' => $factura->archivo])}}

The error I get is a 404 error because the link is trying to access doesn't exist.我得到的错误是 404 错误,因为尝试访问的链接不存在。 In my previous project the link was something like this:在我之前的项目中,链接是这样的:

domainame.com/public/folder/file domainame.com/public/文件夹/文件

I created a symlink to the storage system.我创建了一个指向存储系统的符号链接。 Am I missing another type of configuration or something?我是否缺少另一种类型的配置或其他东西?

I have solved my error, want to post the solution here if people come from a google search or something else:我已经解决了我的错误,如果人们来自谷歌搜索或其他东西,想在这里发布解决方案:

My error was that starting in Laravel 6.0, the variables routes MUST be literal.我的错误是从 Laravel 6.0 开始,变量路由必须是文字。

In my case I changed this:就我而言,我改变了这个:

{{ route('file.show' ,['folder' => 'empresas' , 'file' => $factura->archivo])}}

To this:对此:

{{ route('file.show' ,['foldername' => 'empresas' , 'filename' => $factura->archivo])}}

I broke my mind because I was not seeing that error, hope it helps to anyone that is in my situation我打破了主意,因为我没有看到那个错误,希望它对处于我这种情况的任何人有所帮助

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

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