嗨伙计们,我处于陌生的境地:( 我有一个更新视图,其中我有两个上传文件字段 图像 2.文本文件 在图像部分获取已经保存在db中的图像。但是当我上传cv而不是图像时,cv不会保存在数据库中,而是给我错误
在null 上调用成员函数getClientOriginalName() 为什么会这样呢?
这是我的观点
<form class="checkout woocommerce-checkout" method="post" class="form-horizontal"
action="{{Route('studentUpdateProfile')}}" enctype="multipart/form-data">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 col-lg-offset-3 col-md-offset-3 col-sm-offset-3">
<div class="mj_mainheading mj_toppadder50 mj_bottompadder55">
<h1 style="font-size:35px;"> P<span style="font-size:28px;">ersonal</span> i<span style="font-size:28px;">formation</span>
</h1>
</div>
</div>
<div class="form-group" style="width: 50%; ">
<img id="blah" src="{{ asset("uploads/images/$user->image") }}" alt="User Image" height="150"/>
<br><br>
<input type='file' id="image" name="image" value="image"/>
</div>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 mj_bottompadder20">
<div class="form-group">
<label>Select C.V
</label>
<input type='file' id="cv" name="cv" value="cv"/>
</div>
</div>
</form>
在我的控制器中
public function updateUserProfile(Request $request)
{
$this->validate($request, [
'cv' => 'max:2048',
]);
$image = $request->file('image');
$upload = 'uploads/images';
$filename = $image->getClientOriginalName();
$image->move($upload, $filename);
$file = $request->file('cv');
$upload = 'uploads/cv';
$cv = $file->getClientOriginalName();
$file->move($upload, $cv);
$user = Auth::User();
$user->accountType = $request->accountType;
$user->email = $request->email;
$user->userName = $request->userName;
$user->gender = $request->gender;
$user->dob = $request->dob;
$user->country = $request->country;
$user->city = $request->city;
$user->mobileNo = $request->mobileNo;
$user->cnic = $request->cnic;
$user->address = $request->address;
$user->degreeLevel = $request->degreeLevel;
$user->degreeTitle = $request->degreeTitle;
$user->institution = $request->institution;
$user->degreeCountry = $request->degreeCountry;
$user->degreeCity = $request->degreeCity;
$user->experience = $request->experience;
$user->workExperience = $request->workExperience;
$user->industry = $request->industry;
$user->acedCountry = $request->acedCountry;
$user->image = $filename;
$user->cv = $cv;
$user->save();
return redirect()->back();
}
}
答案 0 :(得分:0)
我做了这个但同样的错误 如何在控制器中设置条件,图像和cv可以是空字段。 意思是aagr image ya cv me se ak select kre to b profile update ho jaye ya ak b nhi krta select tab b upadte ho ????