I work with laravel 6 (last update), I create a form where we could upload an image. I am on Windows OS, I use PHPStorm, laravel and xampp Applications. All my configuration is setting right, no running problems.
My probleme is that I have this error when I submit the reaching fields from my form:
RuntimeException SplFileInfo::getSize(): stat failed for C:\xampp\tmp\phpA5C6.tmp \
Here's the code from my form 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
Here's the code from my controller:
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
]);
The uploaded file code works perfect, I register the file in the selected folder I want. I Have no problem with my routes (no need to show this part of the code). and the database didn't count the record from create post.
and When I submit the form, I have this error:
RuntimeException SplFileInfo::getSize(): stat failed for C:\xampp\tmp\phpA5C6.tmp
and I've checked the upload_max_filesize
in the php.ini
and the UploadedFile.php
in laravel/vendor
and they have the same value.
If you have any ideas... Thank you.