我在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', '[email protected]');
指数
<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() !!}
'如何获取图像到folder'这意味着你不知道如何检索或者你有问题存储图像本身? –
你是什么意思?我的问题是你不能在文件视图中获取图像 –
你的意思是列出所有的图像,如“预览”或获取单页图像? –