我用的是laravel-5.4 make:auth。在register.blade.php中,为用户添加了一个额外的字段配置文件图片。
<form class="form-horizontal" role="form" method="POST" action="{{ route('register') }}" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('image') ? ' has-error' : '' }}">
<label for="image" class="col-md-4 control-label"> Profile picture</label>
<div class="col-md-6">
<input id="image" type="file" class="form-control" name="image">
@if ($errors->has('image'))
<span class="help-block">
<strong>{{ $errors->first('image') }}</strong>
</span>
@endif
</div>
</div>我想将图像路径存储在数据库中。我还执行了:php artisan storage:link和[public/storage]目录已经链接。
app\Http\Controllers\Auth\RegisterController.php:
public function store(Request $request)
{
if($request->hasFile('image')) {
$image_name = $request->file('image')->getClientOriginalName();
$image_path = $request->file('image')->store('public');
$image = Image::make(Storage::get($image_path))->resize(320,240)->encode();
Storage::put($image_path,$image);
$image_path = explode('/',$image_path);
$user->image = $image_path;
$user->save();
} else{
return "No file selected";
}
}web.php
Route::post('/store', 'RegisterController@store');
Route::get('/show', 'RegisterController@show');在数据库中,图像下的用户表作为临时路径存储:
C:xampp\tmp\xampp 762.tmp。
如何存储storage\app\public的图像路径。
发布于 2017-04-16 17:42:18
在控制器中更改此代码
$user->image = $image_path;至
$user->image = Storage::url($image_name);https://stackoverflow.com/questions/43439759
复制相似问题