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.