这里我尝试将用户的图像存储在数据库中,当它们在表单中上传时,当它们上传时,图像存储在数据库中,但是以BIN文件的形式存储,其大小只有7字节或14字节在db中它看起来像[BLOB-14B]和[BLOB-7B]。但是,当我通过直接上传它在数据库上检查它,它工作得很好。这个问题的原因是什么
以下是获取用户形象的表单代码
<div class="form-group">
<label class="col-md-4 control-label">Upload image</label>
<div class="col-md-6">
<input type="file" class="form-control" name="image" id="image">
</div>
</div>
我没有在此处包含整个表单代码,只包含了获取图像文件的代码。
这是控制器功能代码
public function prof_details(Request $request)
{
$post = $request->all();
$val=\Validator::make($request->all(),
[
'firstname' => 'required',
'lastname' => 'required',
'username' => 'required',
'phone'=> 'required',
'nationality' => 'required',
'dobmonth' => 'required',
'dobyear' => 'required',
'dobday' => 'required',
'image' => 'required',
]
);
if ($val ->fails())
{
return redirect()->back()->withErrors($val->errors());
}
else
{
$data = array(
'firstname' => $post['firstname'] ,
'lastname' => $post['lastname'],
'username' => $post['username'],
'phone' => $post['phone'],
'nationality' => $post['nationality'],
'dobmonth' => $post['dobmonth'],
'dobyear' => $post['dobyear'],
'dobday' => $post['dobday'],
'image' =>$post['image'],
);
$updatedata = DB::table('users')->where('name',\Auth::user()->name)
->update($data);
if ($updatedata>0) {
return redirect('home');
}
else
{
return "something";
}
}
}
答案 0 :(得分:0)
<input type="file" class="form-control" name="image" id="image">
文件不存储在$ _POST变量中,而是存储在临时文件中。您可以从$ _FILES变量1 [2]获取此文件的数据。
因此,您上传的文件信息将在$ _POST ['image']中。为了获得实际图像,您需要读取存储在$ _POST ['image'] ['tmp_name']中的临时文件。