简体   繁体   中英

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. 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.

<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('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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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