$attr = [
'error' => 'invalid file extension',
'path' => "\public\html\img\\",
'img' => $_FILES["img_file"]
];
$response->getBody()->write(json_encode($_FILES["img_file"]['type'])); // отображается
$response->getBody()->write('Invalid file extension ('.$_FILES["img_file"]['type'].')');