【问题标题】:Uploaded file can not be opened when clicking the link点击链接时无法打开上传的文件
【发布时间】:2020-12-03 22:32:38
【问题描述】:
                                 {{ trans('cruds.ticket.fields.attachments') }}
                            
                            <td>
                                @foreach($ticket->attachments as $attachment)
                               <a href="{{ $attachment->getUrl() }}">{{ $attachment->file_name }}</a>
                                @endforeach
                            </td>
                        

当我点击链接时显示这样的错误...

找不到对象! 在此服务器上找不到请求的 URL。引用页面上的链接似乎是错误的或过时的。请将该错误告知该页面的作者。

如果您认为这是服务器错误,请联系网站管理员。

错误 404 本地主机 Apache/2.4.43 (Win64) OpenSSL/1.1.1g PHP/7.4.5

【问题讨论】:

  • 嗨,也许打印链接?您可能需要配置 Apache 以提供该目录中的文件或拥有文件下载脚本。

标签: php laravel file


【解决方案1】:

laravel 框架有很好的存储机制。

看到你的代码,我假设, $attachment-&gt;getUrl() 应该返回类似:localhost/abc.img 并且它与 apache 服务器管理的任何资源都不匹配。

所以。让$attachment-&gt;getUrl()返回的链接改成localhost/files/abc.img 并为此链接创建一个路由,例如:

Route::get('files/{filename}', function ($filename)
{
    $file = Storage::get('files/'.$filename);
    $type = $mimetype = Storage::mimeType('product_image/'.$filename);

    $response = Response::make($file, 200);
    $response->header("Content-Type", $type);

    return $response;
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-08
    • 1970-01-01
    • 2015-11-09
    • 2015-09-11
    • 1970-01-01
    • 1970-01-01
    • 2020-03-31
    • 2016-09-20
    相关资源
    最近更新 更多