UploadedFile is missing file extension

Uploaded file does not parse the file extension.

Controller

$gallery->imageFiles = UploadedFile::getInstances($gallery, 'imageFiles');
if ($models = $gallery->uploadImage()) {
    return $this->renderAjax('__galleryItemsAdd', ['models' => $models]);
}

Model

public function uploadImage()
{
    if (!$this->validate()) {
        return false;
    }

    $images = [];
    foreach ($this->imageFiles as $file) { var_dump($file);
        // save images
    }
}

I’m getting this:

array(1) {
  [0]=>
  object(yii\web\UploadedFile)#147 (7) {
    ["name"]=>
    string(29) "photo_2022-09-21_11-48-37.jpg"
    ["tempName"]=>
    string(33) "D:\Programs\XAMPP\tmp\phpEA67.tmp"
    ["type"]=>
    string(10) "image/jpeg"
    ["size"]=>
    int(202336)
    ["error"]=>
    int(0)
    ["fullPath"]=>
    NULL
    ["_tempResource":"yii\web\UploadedFile":private]=>
    NULL
  }
}

I have to resort to this: $extension = strrchr($file->name, '.');
It’s easy enough, but uploadedFile is supposed to have it.

it’s not listed in properties but there is a method getExtension()

Listed in API doc. I haven’t tried.
https://www.yiiframework.com/doc/api/2.0/yii-web-uploadedfile#$extension-detail

Thanks. $file->extension works as a magic getter. I’m not sure why it wasn’t working for me before.

Maybe the docs need updated to remove $extension as a declared property?