public function file($fieldName, array $options = [])
{
if (!$this->config('useCustomFileInput') || isset($options['default']) && $options['default']) {
return parent::file($fieldName, $options);
}
$options += ['_input' => [], '_button' => [], 'id' => $fieldName, 'secure' => true, 'count-label' => __('files selected'), 'button-label' => __('Choose File')];
$fakeInputCustomOptions = $options['_input'];
$fakeButtonCustomOptions = $options['_button'];
unset($options['_input'], $options['_button']);
$options = $this->_initInputField($fieldName, $options);
unset($options['type']);
$countLabel = $options['count-label'];
unset($options['count-label']);
$fileInput = $this->widget('file', array_merge($options, ['style' => 'display: none;', 'onchange' => "document.getElementById('" . $options['id'] . "-input').value = (this.files.length <= 1) ? this.files[0].name : this.files.length + ' ' + '" . $countLabel . "';", 'escape' => false]));
$fakeInputCustomOptions += ['value' => $options['val']['name']];
$fakeInput = $this->text($fieldName, array_merge($fakeInputCustomOptions, ['name' => $fieldName . '-text', 'readonly' => 'readonly', 'id' => $options['id'] . '-input', 'onclick' => "document.getElementById('" . $options['id'] . "').click();", 'escape' => false]));
$buttonLabel = $options['button-label'];
unset($options['button-label']);
$fakeButton = $this->button($buttonLabel, array_merge($fakeButtonCustomOptions, ['type' => 'button', 'onclick' => "document.getElementById('" . $options['id'] . "').click();"]));
return $fileInput . $this->Html->div('input-group', $this->Html->div('input-group-btn', $fakeButton) . $fakeInput);
}