Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

anatomic's avatar

Livewire sometimes considers uploads invalid with no changes

Hi

So I have an infuriating problem, one that has only recently appeared for reasons I cannot fathom. (App unchanged for 5 months, hosted on Forge used regularly with no problems.)

I have a very simple upload form in Livewire.

The file is either a zip or pdf and can be as much as 100mb. Lately, I get told by my validation that "Please ensure you have a zip or pdf file" (It only seems to happen with a largish zip file, it has no issue with small zips. (I don't know the specific size at which it falls over as it is too inconsistent.)

"config/livewire.php" and my "App\Http\Livewire\Upload.php" have the same validation, but removing everything from them apart from 'required|file' allows it to work.

I can add the validation back in (to either file) and it'll work again, but only once. Then I need to edit one of those files in a seemingly random way (remove the mimes, add/remove a zero from max) and it works again. Just once...

Any idea how I can debug what's happening or how I can trouble shoot this please? It only happens on the live server, so I'm debugging this live! (Only I use the app, so I'm fine doing this.)

I also just discovered if I keep clicking submit it eventually works with no edits.

Thanks

0 likes
1 reply
LaryAI's avatar
Level 58

It sounds like you're encountering an intermittent issue with file uploads in Livewire, which can be particularly challenging to debug. However, there are a few steps you can take to troubleshoot this problem.

First, ensure that your Livewire component is handling file uploads correctly. Livewire has specific methods for file uploads that you should be using. Here's a basic example of how a file upload should be handled in a Livewire component:

use Livewire\Component;
use Livewire\WithFileUploads;

class Upload extends Component
{
    use WithFileUploads;

    public $file;

    public function upload()
    {
        $this->validate([
            'file' => 'required|file|mimes:zip,pdf|max:102400', // max is in kilobytes
        ]);

        // Process the file upload...
    }

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

In your livewire.upload view, you should have a file input that uses wire:model:

<form wire:submit.prevent="upload">
    <input type="file" wire:model="file">
    <button type="submit">Upload</button>
    @error('file') <span class="error">{{ $message }}</span> @enderror
</form>

Here are some steps to troubleshoot the issue:

  1. Check PHP Configuration: Ensure that your php.ini configuration on the live server allows for large file uploads. The upload_max_filesize and post_max_size directives should be set to a value that accommodates your file size requirements.

  2. Livewire Configuration: In your config/livewire.php, make sure that the temporary_file_upload configuration is set correctly, with a disk that has enough space and the correct rules for validation.

  3. Error Logging: Add logging to your Livewire component to log any errors that occur during the validation or file upload process. This can help you identify if there are server-side issues that are not immediately apparent.

\Log::info('File upload attempt', ['file' => $this->file]);

try {
    $this->validate([
        'file' => 'required|file|mimes:zip,pdf|max:102400',
    ]);

    // Process the file upload...
} catch (\Exception $e) {
    \Log::error('File upload failed', ['error' => $e->getMessage()]);
    throw $e;
}
  1. Frontend Feedback: Ensure that your frontend is providing immediate feedback if the file is too large or the wrong type before it even hits the server. This can be done with JavaScript or Livewire's built-in validation.

  2. Network Issues: Since the issue is intermittent and occurs with larger files, it could be related to network instability or timeouts. Check your server logs for any network-related errors.

  3. Livewire Version: Ensure that you are using the latest version of Livewire, as there may have been bug fixes related to file uploads in recent updates.

  4. Browser Developer Tools: Use the network tab in your browser's developer tools to monitor the file upload request. Check for any failed requests or errors that might provide clues.

  5. Server Permissions: Verify that the server has the correct permissions to write to the temporary directory used by Livewire for file uploads.

By following these steps, you should be able to narrow down the cause of the issue. If the problem persists, consider reaching out to the Livewire community or support for further assistance.

Please or to participate in this conversation.