0
이미지/pdf를 내 폴더에 업로드하고 laravel 5.2를 사용하여 데이터베이스에 이름을 저장하려고합니다. 모든 필드를 채우더라도 모든 버튼을 클릭 할 때마다 서버 측 유효성 검사 오류가 발생했습니다.Laravel 5.2 파일 업로드가 작동하지 않습니다.
아래는 내보기이다 (이제 입력 필드를 파일 제공. 또한 나는 형태로 좀 더 필드가)
public function add_infrastructure() {
$rules = array(
'infrastructure_type_id' => 'required',
'type_of_waste' => 'required|regex:/^[(a-zA-Z\s)]+$/u',
'waste_quantity' => 'required|numeric',
'type_of_residues'=> 'required',
'residues_quantity' => 'required',
'utility_value' => 'required',
'attachments' => 'required|mimes:jpeg,jpg,png|max:10000'
);
$validation = Validator::make(Input::all(), $rules);
if ($validation->fails())
{
return Redirect::to('/college/infrastructure')->withErrors($validation);
}
else{
$files = Input::file('attachments');
$rules = array('files' => 'required');
$validator = Validator::make(array('files'=> $files), $rules);
if($validator->passes()){
$destinationPath = 'uploads/infrastructure';
$filename = $files->getClientOriginalName();
$path = $destinationPath.'/'.$filename;
$upload_success = $files->move($destinationPath, $filename);
$maildata['attachments']=$filename;
}
$user = Auth::user()->id;
$maildata['college_id'] = College::select('id')->where('user_id',$user)->first()->id;
$maildata['registration_id'] = Registration::select('id')->where('college_id',$maildata['college_id'])->first()->id;
$save = $this->save_data($maildata, 'ClgInfrastructure');
$result = ClgInfrastructure::where('college_id',$maildata['college_id'])->where('registration_id',$maildata['registration_id'])->orderBy('id', 'desc')->get()->toArray();
return redirect($current_url)->with('successmsg','Added Information Successfully.');
}
}
결과는 항상이다
{!! Form::open(array('url' => 'college/add_infrastructure', 'role' =>
'form', 'method' => 'post', 'class' => 'clsForm', 'onsubmit'=>'return
validateFormAddClient();', 'files'=> true)) !!}
<div class="form-group">
<label for="exampleInputEmail1">Upload Attachments</label>
<input type="file" name="attachments" id="attachments">
<span id="error_attachments" style="color:#e03b3b;"> </span>
</div>
{!! Form::close() !!}
컨트롤러 유효성 검증 오류 : '필수'. 미리 감사드립니다.