我尝试使用Laravel控制器上传图片
public function store(Request $request)
{
$new=new Verify;
$new->user_id=Auth::id();
$new->message=$request->message;
if($request->hasfile('image'))
{
$file=$request->file('image');
$extension=$file->getClientOriginalExtension();
$filename=time() ."." . $extension;
$file->move('uploads/Verify',$filename);
$new->image=$filename;
}
$new->save();
return redirect()->back();
我的迁移表如下
public function up()
{
Schema::create('verifies', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('user_id')->nullable();
$table->string('message')->nullable();
$table->string('image')->nullable();
$table->timestamps();
});
}
诸如用户ID和消息之类的字段已被填充,但图像字段仍为空 代码的html如
<table class="table">
<tr>
<th>Your message</th>
</tr>
<tr>
<td>
<form action="{{route('Verifying')}}" method="POST">
@csrf
<textarea name="message" id="message" cols="5" rows="5"></textarea>
</td>
</tr>
<tr>
<th>Your Cnic</th>
</tr>
<tr>
<td>
<input type="file" name="image" id="image">
</td>
</tr>
<tr>
<td>
<input type="submit">
</td>
</tr>
</form>
</table>
任何人都可以指导我怎么了吗?为什么图片没有上传...
答案 0 :(得分:0)
使用province
发送表单,它应该可以工作
sigla_provincia
然后它将起作用
为什么我们添加enctype="multipart/form-data"
enctype属性指定将表单数据提交到服务器时应如何编码。