File upload error – unable to create a temporary file. PHP/HERD/LARAVEL

I’m using the following stack:

  • Laravel Herd
  • Laravel v12.0
  • PHP v8.2.28
  • maatwebsite/excel v3.1 (Laravel Excel)
  • Postman
  • Windows 10 OS

What I’m Trying to Do

I want to send a POST request containing an Excel file (.xlsx). This file should then be processed using the maatwebsite/excel package to create new records based on its contents.

The Problem

When I send the POST request using Postman with form-data containing the Excel file, I get this error:

Warning: File upload error - unable to create a temporary file in Unknown on line 0

Here’s a screenshot for more details:
error screnshoot

Here’s my code

routesapi.php

Route::controller(AlumniController::class)->group(function () {
    ...
    Route::post('/alumnis/import', 'importExcel'); // this is the endpoint for import excel
});

appHttpControllersAlumniController.php

use IlluminateHttpRequest;
use AppImportsAlumnisImport;
use MaatwebsiteExcelFacadesExcel;

class AlumniController extends Controller
{
    ...

    public function importExcel()
    {
        try {
            Excel::import(new AlumnisImport, request()->file('alumni_excel'));
        } catch (Throwable $th) {
            dd($th);
        }
    }
}
appImportsAlumnisImport.php

use AppModelsAlumni;
use AppModelsJurusan;
use MaatwebsiteExcelConcernsToModel;

class AlumnisImport implements ToModel
{
    /**
     * @param array $row
     *
     * @return IlluminateDatabaseEloquentModel|null
     */
    public function model(array $row)
    {
        $jurusan = Jurusan::firstOrCreate(
            ['nama' => $row['nama_jurusan']],
            ['nama' => $row['nama_jurusan']]
        );

        return new Alumni([
            'nama' => $row['nama'],
            'tgl_lahir' => $row['tgl_lahir'],
            'tahun_mulai' => $row['tahun_mulai'],
            'tahun_lulus' => $row['tahun_lulus'],
            'no_tlp' => $row['no_tlp'],
            'email' => $row['email'],
            'password' => isset($row['password']) ? $row['password'] : null,
            'alamat' => $row['alamat'],
            'tempat_kerja' => $row['tempat_kerja'] ?? null,
            'jabatan_kerja' => $row['jabatan_kerja'] ?? null,
            'tempat_kuliah' => $row['tempat_kuliah'] ?? null,
            'prodi_kuliah' => $row['prodi_kuliah'] ?? null,
            'kesesuaian_kerja' => isset($row['kesesuaian_kerja']) ? filter_var($row['kesesuaian_kerja'], FILTER_VALIDATE_BOOLEAN) : null,
            'kesesuaian_kuliah' => isset($row['kesesuaian_kuliah']) ? filter_var($row['kesesuaian_kuliah'], FILTER_VALIDATE_BOOLEAN) : null,
            'photo' => $row['photo'] ?? null,
            'jurusan_id' => $jurusan->id,
        ]);
    }
}

Need Help

Has anyone experienced this issue before? Could it be related to Laravel Herd? I’d really appreciate any help or suggestions to solve this. If you need more info, feel free to leave a comment. Thanks