【问题标题】:Laravel8 storage link won't work on productionLaravel 8 存储链接不适用于生产
【发布时间】:2022-01-12 22:39:34
【问题描述】:

我在 Laravel8 中的存储链接有问题,一切正常,直到我将项目从 localhost 移动到托管,它与 public_html 一起工作,我的结构如下。

LaravelAPP
--app
--boostrap
--config
--database
--storage
--...

public_html
--img
--storage
-- .htaccess
-- index.php
-- ... 

在 localhost 中,public 文件夹位于 LaravelAPP 文件夹中,但在托管中,我必须将其内容放在 public_html 中。

这是我保存文档的函数片段,它正确地执行了它,它将它们保存在 LaravelAPP 内部的存储文件夹中,但它在 public_html 中没有做同样的事情(我担心因为它不是正确执行符号链接)。

$document->attach_image = $image->storeAs("public/image/$year/$user", $name_image);
$document->attach_pdf = $pdf->storeAs("public/pdf/$year/$user", $name_pdf);

当我在应用程序中保存图像或 pdf 时,我得到以下 URL,因此它可以很好地创建上面的代码,但它向我显示 404 |未找到,因为它不是在 public_html 中创建的,不能显示任何内容。

https://mydomain/storage/pdf/2022/darkvayder/pdf-test.pdf

我尝试在filesystems.php文件中添加以下内容,但没有生效,我认为公共文件夹的链接仍然创建。

'links' => [
        public_path('public_html/storage') => storage_path('app/public'),
],

【问题讨论】:

    标签: php filesystems subdomain laravel-8 public-html


    【解决方案1】:

    如果您在共享主机上并且无法访问命令行,则可以通过在 web.php 中使用此路由来建立到公共文件夹的链接:

    Route::get('/linkstorage', function () { $targetFolder = base_path().'/storage/app/public'; $linkFolder = $_SERVER['DOCUMENT_ROOT'].'/storage'; symlink($targetFolder, $linkFolder); });
    

    【讨论】:

    • 您好,感谢您的回复,我已经尝试过了,当我输入 /linkstorage 时出现 500 服务器错误。这应该发生吗?
    猜你喜欢
    • 2018-11-16
    • 1970-01-01
    • 1970-01-01
    • 2018-02-22
    • 2016-11-14
    • 2018-02-28
    • 2013-11-08
    • 2020-04-19
    • 1970-01-01
    相关资源
    最近更新 更多