我使用 laravel 6(上次更新),我创建了一个可以上传图片的表单。我在 Windows 操作系统上,我使用 PHPStorm、laravel 和 xampp 应用程序。我所有的配置都设置正确,没有运行问题。
我的问题是,当我从表单提交到达字段时出现此错误:
RuntimeException SplFileInfo::getSize(): stat failed for C:\xampp\tmp\phpA5C6.tmp \
这是我的表单 create.blade.php 中的代码:
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Creat Post</div>
<div class="card-body">
@if(count($errors) > 0)
<ul>
@foreach($errors->all() as $error)
<li class="alert alert-danger alert-dismissible fade show">
<strong>{{$error}}</strong>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</li>
@endforeach
</ul>
@endif
<form action="{{route('post.store')}}" method="POST" enctype="multipart/form-data" >
@csrf
<div class="form-group">
<label for="title">Title</label>
<input type="text" name="title" class="form-control" id="title" aria-describedby="title" placeholder="Type Your Title">
</div>
<div class="form-group">
<label for="category">Category</label>
<select class="form-control" name="category_id" id="category">
<option value="0" selected disabled>Select A Category</option>
@foreach($categories as $category)
<option value="{{$category->id}}">{{$category->name}}</option>
@endforeach
</select>
</div>
<div class="form-group">
<label for="content">Content</label>
<textarea class="form-control" name="content" id="content" rows="4" cols="4" placeholder="Type Your Content"></textarea>
</div>
<div class="form-group">
<label for="image">Image</label>
<input type="file" name="image" id="image" class="form-control-file">
</div>
<button type="submit" class="btn btn-primary">Save</button>
</form>
</div>
</div>
</div>
</div>
</div>
@endsection
这是我的控制器的代码:
public function store(Request $request)
{
$data = $this->validate($request, [
"title" => "required|string",
"content" => "required|string",
"category_id" => "required",
"image" => "required|image"
]);
$file = $request->image;
$destinationPath = public_path().'/uploads/posts';
$filename = $destinationPath . '' . time() . '.' . $file->getClientOriginalExtension();
$uploaded = $file->move($destinationPath,$filename);
$post = Post::create([
"title" => $request->title,
"content" => $request->content,
"category_id" => $request->category_id,
"image" => $uploaded
]);
上传的文件代码完美运行,我在我想要的选定文件夹中注册文件。我的路线没有问题(无需显示这部分代码)。并且数据库没有计算来自创建帖子的记录。
当我提交表单时,我有这个错误:
RuntimeException SplFileInfo::getSize(): stat failed for C:\xampp\tmp\phpA5C6.tmp
我已经检查了upload_max_filesize
inphp.ini
和UploadedFile.php
inlaravel/vendor
并且它们具有相同的值。
如果您有任何想法...谢谢。