사용자가 Laravel Authentication을 사용하여 이름, 전자 메일, 암호 및 dob와 같은 자격 증명을 사용하여 자신의 프로필 사진을 업로드 할 수있는 웹 사이트를 만들고 있습니다. 여기Laravel 등록 사진 업로드
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'dob' => $data['dob'],
'profile_picture' => $data['profile_picture],
]);
}
및 내 양식은 다음과 같습니다 :
php artisan make:auth
을 수행 한 후, AuthController.php
에서이 기능이있다
<form class="form-horizontal" role="form" method="POST" action="{{ url('/register') }}" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-mail Address</label>
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}">
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Password</label>
<input id="password" type="password" class="form-control" name="password">
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
<div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }}">
<label for="password-confirm" class="col-md-4 control-label">Confirm Password</label>
<input id="password-confirm" type="password" class="form-control" name="password_confirmation">
@if ($errors->has('password_confirmation'))
<span class="help-block">
<strong>{{ $errors->first('password_confirmation') }}</strong>
</span>
@endif
</div>
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
<label for="name" class="col-md-4 control-label">Fullname</label>
<input id="name" type="text" class="form-control" name="name" value="{{ old('name') }}">
@if ($errors->has('name'))
<span class="help-block">
<strong>{{ $errors->first('name') }}</strong>
</span>
@endif
</div>
<div class="form-group{{ $errors->has('dob') ? ' has-error' : '' }}">
<label for="name" class="col-md-4 control-label">Date of Birth</label>
<input id="dateOfBirth" type="date" class="form-control" name="dob">
@if ($errors->has('dob'))
<span class="help-block">
<strong>{{ $errors->first('dob') }}</strong>
</span>
@endif
</div>
<div class="form-group{{ $errors->has('profile_picture') ? ' has-error' : '' }}">
<label for="name" class="col-md-4 control-label">Profile Picture</label>
<input id="profilePicture" type="file" class="form-control" name="profile_picture">
@if ($errors->has('profile_picture'))
<span class="help-block">
<strong>{{ $errors->first('profile_picture') }}</strong>
</span>
@endif
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">
<i class="fa fa-btn fa-user"></i> Register
</button>
</div>
</form>
나는 그것의 확장자를 가진 이미지 파일 이름을 저장하고 싶습니다. 하지만 어떻게해야합니까? 문자열로 파일 이름을 가져 오는 방법, 이미지 파일을 공용 폴더로 이동 한 다음 XAMPP 데이터베이스에 저장하는 방법은 무엇입니까? 그냥 이름을 저장하고 profile_images 폴더에 공용 디렉토리에 업로드 할 경우
protected function create
,이 같은 작업을 수행 할 수 있습니다. 현실에서는 DB에 이미지를 저장하지 않습니다! 서버의 해당 이미지에 "문자열"경로 만 저장합니다! – lewis4u@ lewis4u 예! 그게 내가 원하는거야! 문자열 만이 파일 이름입니다. –