skip to Main Content

I started learning Laravel 9 livewire. I am trying to make an image upload application. I did the exact example in the Livewire documentation, but I get an error that the image could not be uploaded. When I do the same application on my mac computer, it works without any problems. It doesn’t work when I do it on my windows computer.

ImageUpload.php

<?php

namespace AppHttpLivewire;

use LivewireComponent;
use LivewireWithFileUploads;

class ImegaUpload extends Component
{
    use WithFileUploads;

    public $photo;

    public function save()
    {
        $this->validate([
            'photo' => 'image|max:1024', // 1MB Max
        ]);

        $this->photo->store('photos');
    }


    public function render()
    {
        return view('livewire.imega-upload');
    }
}

image-upload.blade.php


<div>
    <h1>Image upload</h1>
    <form wire:submit.prevent="save">
        <input type="file" wire:model="photo">

        @error('photo')
            <span class="error">{{ $message }}</span>
        @enderror

        <button type="submit">Save Photo</button>
    </form>
</div>

Error
enter image description here

I’m doing the example in the Livewire documentation but still getting the error. Not even the livewire-temp folder is created.

2

Answers


  1. Look like your PHP.ini is missing

    sys_temp_dir

    and

    upload_tmp_dir

    uncomment and then set its value.

    mine example.

    Laragon on win 10:

    sys_temp_dir = "claragontmp"

    upload_tmp_dir = "claragontmp"

    all temp files will go to that location (not just uploaded)

    Login or Signup to reply.
  2. In
    AppHttpMiddlewareTrustProxies
    change
    protected $proxies;
    to
    protected $proxies = '*';
    it helped me

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search