簡體   English   中英

上傳圖片並訪問laravel 5

[英]upload image and access laravel 5

我在laravel 5中工作,我想上傳用戶的個人資料圖片。 我的上傳正常,但是我不知道如何將圖像保存到文件夾中。 有人可以幫我嗎?

調節器

public function updateProfile() {
    $profileData = Input::except('_token');
    $validation = Validator::make($profileData, User::$profileData);
    if ($validation->passes()) {
        $file = array_get($profileData,'imagem');
        $destinationPath = 'imagens/perfil';
        $extension = $file->getClientOriginalExtension();
        $fileName = rand(11111, 99999) . '.' . $extension;
        $upload_success = $file->move($destinationPath, $fileName);
        User::where('id', Input::get('id'))->update($profileData);
        return view('backend/perfil.index')->with('message', 'Updated Succesfully');
    } else {
        return view('backend/perfil.index')->with('message', $validation->messages());
    }
}

路線

Route::post('backend/perfil', 'BackendControlador@updateProfile');

指數

    <div class="col-md-3 col-lg-3 " align="center"> 
        <img alt="User Pic" src="{{ Auth::user()->imagem}}" class="img-circle img-responsive"> 
    </div>


{!! Form::open(array('class' => 'form-horizontal', 'url' => 'backend/perfil', 'name' => 'updateProfile', 'role' => 'form', 'files'=> true))!!}

        <input type="hidden" name="id" value="{{Auth::user()->id}}">


        <div class="row" style="margin-bottom: 20px;">
            <div class="col-md-3 col-lg-3"></div>
            <div class="col-md-2 col-lg-2">
                {!! Form::label('imagem', 'Imagem', ['class' => 'label_perfil']) !!}
            </div>
            <div class="col-md-5 col-lg-5">
                {!! Form::file('imagem', ['class' => 'input-file']) !!}
            </div>
        </div>   
        <div class="row" style="margin-bottom: 20px; margin-top: 30px;">
            <div class="col-md-3 col-lg-3"></div>
            <div class="col-md-9 col-lg-9">
                {!! Form::submit('Alterar perfil', ['class' => 'btn btn-primary']) !!}
            </div>
        </div> 
    {!! Form::close() !!}

從操作的評論中,我猜想操作沒有將圖像的路徑保存在數據庫中。

你該怎么做

第1步 :

每當保存圖像時,都應以某種身份將圖像的路徑保存在數據庫中。

第2步 :

從數據庫檢索圖像的路徑,並將其放在img src標記內

$yourImagePath = 'xyz.jpg'; # Retrieved from DB

然后

<img src='<?php echo $yourImagePath?>'>

代替這條線

$destinationPath = 'imagens/perfil'; 

只需嘗試以下代碼

$destinationPath = publicpath().'imagens/perfil';

暫無
暫無

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

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