# \[SOLVED\]How to check file extension for file input and display the given error message?

**URL:** <https://discourse.cakephp.org/t/solved-how-to-check-file-extension-for-file-input-and-display-the-given-error-message/1607>\
**Category:** Need Help\
**Created:** [November 25, 2016, 2:44pm UTC](https://discourse.cakephp.org/t/solved-how-to-check-file-extension-for-file-input-and-display-the-given-error-message/1607 "2016-11-25T14:44:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ndgAlainB](https://avatars.discourse-cdn.com/v4/letter/n/9d8465/32.png) [@ndgAlainB](https://discourse.cakephp.org/u/ndgAlainB)\
**Post date:** [November 25, 2016, 2:44pm UTC](https://discourse.cakephp.org/t/solved-how-to-check-file-extension-for-file-input-and-display-the-given-error-message/1607/1 "2016-11-25T14:44:57Z")

</div>

Hello,  
I want to check the extension of an uploaded file so my form is:  
(Don’t worry about FormB which simply use CakePHP Bootstrap plugin)

```
<?= $this->FormB->create($site, ['horizontal' => true, 'type' => 'file']) ?>
    <?= $this->FormB->input('guide.fileCard', ['label' => __("upload your card"), 'type' => 'file']); ?>
<?= $this->FormB->end() ?>

```

And my GuidesTable.php is:

```
public function validationDefault(Validator $validator) {
	$validator
	    ->allowEmpty('id', 'create')
	    ->add('id', 'valid', ['rule' => 'numeric'])
	    ->add('site_id', 'valid', ['rule' => 'numeric'])
	    ->add('fileCard', 'file', [
			'rule' => ['uploadedFile' => ['types' => ['image/png', 'image/jpeg', 'application/pdf']]], // It's what I expect to check
			'message' => __("authorized extensions: jpg, png, pdf")
			]);
	
	return $validator;
}

```

Guide.php:

```
class Guide extends Entity {

protected $_accessible = [
	'site_id' => true,
	'card' => true,
	'fileCard' => true,
];
}

```

But I get the following error:

```
`Error: Unable to call method "Array" in "default" provider for field "fileCard"`
```

---

<div class="post-metadata">

**Author:** ![ndgAlainB](https://avatars.discourse-cdn.com/v4/letter/n/9d8465/32.png) [@ndgAlainB](https://discourse.cakephp.org/u/ndgAlainB)\
**Post date:** [November 25, 2016, 4:05pm UTC](https://discourse.cakephp.org/t/solved-how-to-check-file-extension-for-file-input-and-display-the-given-error-message/1607/2 "2016-11-25T16:05:42Z")

</div>

Sorry, syntax error after `uploadedFile`

```
public function validationDefault(Validator $validator) {
$validator
    ->allowEmpty('id', 'create')
    ->add('id', 'valid', ['rule' => 'numeric'])
    ->add('site_id', 'valid', ['rule' => 'numeric'])
    ->add('fileCard', 'file', [
		'rule' => ['uploadedFile', ['types' => ['image/png', 'image/jpeg', 'application/pdf']]], // It's what I expect to check
		'message' => __("authorized extensions: jpg, png, pdf")
		]);

return $validator;
}
```
