“Undefined array key 0” when uploading an image
Solution
It was a issue with my local php environment. After using a newer PHP version or testing it on my live server it works.
If you get this issue, try install Laravel Herd or make a clean php install.
What I’m trying to do and why
I’m building an admin interface with Laravel 12, Filament 3.3 to manage my menu categories. Each category should optionally have a cover image:
What I did so far
- Added the cover_image column via migration and included it in my Category model’s $fillable.
- Ran php artisan view:clear, config:clear, etc.
- Enforced single-file upload with multiple(false) and maxFiles(1).
- created a single resource just for file uploads to test it
Still, the upload process fails with:
Relevant parts of my setup
Question:
How can I configure the FileUpload so that Filament/Livewire handles cover_image without throwing “Undefined array key 0”? Any guidance or tips are greatly appreciated!
Solution:Jump to solution
Soo, that's interesting... It works now. I believe it was a issue with my php version.
I installed 8.4 and it works, I also installed Herd and it seems like a good application... I will work with it...
24 Replies
You don’t need both multiple and max files. Use one or the other.
I think the
cover_image
still needs to be cast to an array
even if it's a single oneBoth do not work
Can you check the network requests? Sounds like some issue directly with Livewire. It seems it can't find the temp file.



I mean network requests via your Dev Tools.


What's the response of
file-upload
?{"paths":[]}
It should look something like this:
So for some reason your file uploads fail.
What dev environment do you use? Is this on Windows?
Yes
Laragon?
Nope, just normal dev env in PHPStorm
What is "normal dev env"?
I created just a normal project within PHPStorm, run composer commands if needed, or artisan commands. MySQL Workbench and for php I use scoop
Do you have a
upload_tmp_dir
set in your php.ini?No
I guess that's the issue. Set a dir where the tmp files should be stored.
So I set
and it still dont work
Can you check whether the setting is actually applied via
ini_get('upload_tmp_dir')
Yes, I already checked it.
It is
Hm, I'm out of ideas. I'd verify whether you can upload a file via a simple form with pure PHP backend. If not it's probably related to your dev env.
Have you tried Herd for Windows? Maybe it works better.
Solution
Soo, that's interesting... It works now. I believe it was a issue with my php version.
I installed 8.4 and it works, I also installed Herd and it seems like a good application... I will work with it
Great!