jaredatobe
jaredatobe
FFilament
Created by jaredatobe on 5/8/2025 in #❓┊help
Get filename and path after a file is uploaded using afterStateUpdated
I tried that early on and [0] throws an error ("Undefined array key 0"). I tried numerous variations of brackets and arrows and none of them work. I've tried casting the object as an object and as an array (which is technically possible) in order to access what's inside of it. If I call the array with the GUID $livewire->data['23a1df3...'] I can get to the object directly, but ['path'] doesn't work. So I tried reset() to get at the zeroth element of the associative array, which worked, but again ['path'] doesn't work. So I tried ->getPath() and all I got is the part I already know: C:\xampp\htdocs\<projectname>\storage\app\livewire-tmp, the path up to but not including the filename of the uploaded file. What am I missing? [Update]: Found it. I was missing getFilename(). This works:
$temporaryuploadedfileobject = $livewire->data['existing_policy'];
$filename = reset($temporaryuploadedfileobject)->getFilename();
"EsyyO09GAzYENzZyhSjpfMlJLV28iV-metaQXV0b2RpZGFjdGljaXNtMiAtIFdpa2lwZWRpYS5wZGY=-.pdf"
$temporaryuploadedfileobject = $livewire->data['existing_policy'];
$filename = reset($temporaryuploadedfileobject)->getFilename();
"EsyyO09GAzYENzZyhSjpfMlJLV28iV-metaQXV0b2RpZGFjdGljaXNtMiAtIFdpa2lwZWRpYS5wZGY=-.pdf"
So the one-liner answer is this:
$filename = reset($livewire->data['myfieldname'])->getFilename();
$filename = reset($livewire->data['myfieldname'])->getFilename();
Thanks for the help!
9 replies
FFilament
Created by jaredatobe on 5/8/2025 in #❓┊help
Get filename and path after a file is uploaded using afterStateUpdated
No description
9 replies
FFilament
Created by jaredatobe on 5/8/2025 in #❓┊help
Get filename and path after a file is uploaded using afterStateUpdated
$livewire works as suggested. It appears to have roughly the same information available as $component. However, what I'm asking for is how to get to the uploaded filename. dd shows me the filename, buried in the data array, but how do I access that programmatically? The linked answeroverflow answer uses $this->form->getRawState() which throws an error if I try to use it inside the resource class, so I don't even know how to use it.
9 replies