簡體   English   中英

如何在Laravel上的公共存儲鏈接中顯示用戶文件夾中的圖像

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

我有一個Laravel應用,該應用具有指向公用文件夾的存儲鏈接,並且我試圖在該應用的視圖中顯示圖像。 但是,我不確定如何使用存儲文件夾的結構方式。

基本上,該文件夾以用戶名開頭,然后具有子文件夾,例如聯系人,文件,圖像等。該應用程序應在個人資料視圖的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>

我嘗試將鏈接指向URL中的鏈接:

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

但是,當我加載頁面時,圖像不會顯示,甚至不會保存。 這是從視圖功能加載圖像的正確方法嗎?

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

程序應如何從存儲中的用戶文件夾加載圖像?

`

您的代碼未指向正確的文件夾路徑。 你可以試試這個

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

嘗試使用符號鏈接來訪問數據。

php artisan storage:link

參考: https : //laravel.com/docs/5.4/filesystem

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM