简体   繁体   English

如何在Laravel上的公共存储链接中显示用户文件夹中的图像

[英]How to display images from user folder in public storage link on laravel

I have a Laravel app with a storage link to the public folder, and I'm trying to display an image in the view of the app. 我有一个Laravel应用,该应用具有指向公用文件夹的存储链接,并且我试图在该应用的视图中显示图像。 However, I'm not sure how to do so with the way the storage folder is structured. 但是,我不确定如何使用存储文件夹的结构方式。

Basically, the folder starts with the user's name, then has sub-folders, such as contacts, files, images, etc. The app is supposed to display the user's image within the src tag for the profile view. 基本上,该文件夹以用户名开头,然后具有子文件夹,例如联系人,文件,图像等。该应用程序应在个人资料视图的src标记内显示用户图像。

<div class="container">
    <div class="row">
        <div class="col-md-10 col-md-offset-1">
            <img class="profileImage" src="{{ url('storage/{{ Auth::user()->name }}/images/{{ $profileImage }}') }}" style="width: 150px; height: 150px; float: left; border-radius: 10%; margin-right: 25px;">
            <h2>{{ Auth::user()->name }}</h2>
            <form enctype="multipart/form-data" action="{{ route('profile.update') }}" method="post">
                <label>Update Profile</label>
                <input type="file" name="profileImage" id="profile-image">
                <input type="hidden" name="_token" value="{{ csrf_token() }}">
                <input type="submit" class="pull-right btn btn-sm btn-primary">
            </form>
        </div>
    </div>
</div>

I tried directing to a link within the url: ` 我尝试将链接指向URL中的链接:

{{ url('storage/app/public/{{ Auth::user()->name }}/images/{{ $profileImage }}`

However, when I load the page, the image is not displayed, or even saved. 但是,当我加载页面时,图像不会显示,甚至不会保存。 Is this the proper way to load the image from the view function?` 这是从视图功能加载图像的正确方法吗?

public function getUserProfile()
{
    return view('users.profile', ['user' => Auth::user()]);
}`

How should the program load the image from the user folder in storage? 程序应如何从存储中的用户文件夹加载图像?

` `

Your code does not point to correct folder path. 您的代码未指向正确的文件夹路径。 You could try this 你可以试试这个

url('storage/app/public/{{ Auth::user()->name }}/images/{{ $profileImage }}')

Try to use symbolic link to access the data. 尝试使用符号链接来访问数据。

php artisan storage:link

refer : https://laravel.com/docs/5.4/filesystem 参考: https : //laravel.com/docs/5.4/filesystem

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

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