【问题标题】:How to access image from storage folder in Laravel Homestead (Symbolic Links problem)?如何从 Laravel Homestead 的存储文件夹中访问图像(符号链接问题)?
【发布时间】:2020-08-15 13:31:49
【问题描述】:

我试图弄清楚如何访问存储的文件,在这种情况下是个人资料图片。

理想情况下,我想将它们保存在“个人资料图片”文件夹中。可以使用指向 storage/app/public/profilepictures 的符号链接在 public/profilepictures 目录中

我现在的代码如下所示:

控制器:

    //store our image in the profilepics directory
    $profilepicpath = request('profilepic')->store('profilepictures', 'public');

    //actually write all the data to the database
    auth()->user()->profile()->create([
        'profilepic' => $profilepicpath,
        'dateofbirth' => $data['dateofbirth'],
        'about' => $data['about'],
        'zipcode' => $data['zipcode'],
        'state' => $data['state']
    ]);

查看:

<div class="data" style="visibility: hidden;">
    {{$profile = App\profile::find(Auth::user()->id)}}
</div>
    <div class="profile-wrapper">
        <div class="profile-grid">
            <div class="profilepic">
            <img class="profilepic-image" src={{asset($profile['profilepic'])}}>
            </div>

Config 中的 Filesystems.php:

/*
|--------------------------------------------------------------------------
| Symbolic Links
|--------------------------------------------------------------------------
|
| Here you may configure the symbolic links that will be created when the
| `storage:link` Artisan command is executed. The array keys should be
| the locations of the links and the values should be their targets.
|
*/

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

有人知道为什么这不起作用吗?

我可以确认下面有一个符号链接,它似乎指向正确的位置:

如果我从应该在视图中显示的位置复制图像位置,我会得到以下结果之一:

或者

这两个链接都不起作用,如果我尝试在浏览器中访问它,我只会收到错误 404。虽然基于查看目录结构,我认为第一个应该可以工作。

大家有什么建议吗?

我在安装在 ubuntu 物理桌面上的 virtualbox vm 上的 homestead 上运行 laravel,到目前为止我已经为此尝试了许多不同的配置,包括编辑 .htaccess 文件都没有成功。

【问题讨论】:

    标签: php laravel symlink public homestead


    【解决方案1】:

    好的,所以在这个特定的实例中,唯一的问题是当我第一次运行 php artisan storage:link 命令时,我是从我的主机而不是我的虚拟机运行它...因为我使用的是 Homestead (vm) all我需要做的是 vagrant destroy ,然后重新创建 VM 并从 VM 终端运行 php artisan storage:link 命令,并且效果很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-22
      • 2017-05-02
      • 2022-08-24
      • 1970-01-01
      • 2017-12-29
      相关资源
      最近更新 更多