【问题标题】:Access forbidden! You don't have permission to access the requested directory. There is either no index document or the directory is read-protected禁止访问!您无权访问请求的目录。没有索引文档或目录被读保护
【发布时间】:2021-06-20 02:06:15
【问题描述】:

我从昨天开始在我的 laravel 项目中遇到了一个问题。我有一个输入文件,该文件上传到 forder storage/app/public/uploads。 现在,当我想显示该文件时,我收到以下消息:“禁止访问!您无权访问请求的目录。没有索引文档或目录被读保护。”

<td><a class="" style="text-decoration: underline;" href="{{ asset('storage/app/public') }}/uploads/{{ $row->file }}"  target="_blank" style="color:black;font-size:120%">{{ $row->name }}</a></td>

我该如何解决这个问题。

【问题讨论】:

  • 确保 $row->file 不为空或为目录。

标签: laravel file-upload storage show


【解决方案1】:

您需要公开该文件。

https://laravel.com/docs/8.x/filesystem#the-public-disk

运行工匠命令php artisan storage:link

这将创建一个从public/storagestorage/app/public 的符号链接

然后你可以使用 Laravel 助手来提供文件

https://laravel.com/docs/8.x/helpers#method-storage-path

storage_path('app/public/uploads/' . $row-&gt;file)

【讨论】:

    猜你喜欢
    • 2020-05-19
    • 2020-06-27
    • 2015-12-19
    • 1970-01-01
    • 2015-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多