I am developing an application using Laravel 12 and Livewire, hosted locally on Laragon. Initially, the file upload feature worked perfectly. I was able to upload images successfully, and they were saved correctly in the storage/app/public directory.
However, today, I noticed that the upload functionality has stopped working:
<?php
namespace App\Livewire;
use Livewire\Component;
use Livewire\WithFileUploads;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Storage;
class CreateDonasi extends Component
{
use WithFileUploads;
public $image;
public function submit()
{
$this->validate([
'image' => 'required|image|max:5120',
]);
if ($this->image) {
$filename = Str::random(30) . '.' . $this->image->getClientOriginalExtension();
$filePath = $this->image->storeAs('donations', $filename, 'public');
}
}
public function render()
{
return view('livewire.create-donasi');
}
}
<form wire:submit.prevent="submit" class="space-y-6">
<!-- Upload Gambar -->
<div>
<label class="block text-sm font-medium text-gray-700">Gambar (opsional)</label>
<input wire:model="image" type="file" accept="image/*"
class="mt-1 block w-full p-3 rounded-xl border border-gray-300 shadow-sm focus:border-blue-500 focus:ring focus:ring-blue-200 focus:ring-opacity-50" />
@error('image') <p class="text-red-600 text-sm mt-1">{{ $message }}</p> @enderror
</div>
</div>
</form>
Environment details:
Laravel Version: 12
PHP Version: 8.4
Local Server: Laragon
Os: Windows
Steps I have already tried:
This issue didn’t occur when I tested the functionality yesterday. The image upload worked perfectly then, but now it fails as if no file is being sent in the request.
What could have changed or caused this issue? How can I debug or resolve this behavior?
Any insights or suggestions would be greatly appreciated!
I resolved the error by uncommenting the upload_tmp_dir
directive in my php.ini
file and setting it to c:\windows\temp
. After this change, everything worked as expected. The solution was found here Link