【发布时间】:2017-09-12 09:06:19
【问题描述】:
我正在使用 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\phpC762.tmp.
如何存储storage\app\public的图片路径。
【问题讨论】:
标签: database image laravel file-upload laravel-5.4