0

Hello I have added accept in file input type and when i upload png image it show error Please enter a value with a valid extension. searched a lot and tried different ways but couldn't figure out.

Below is the code for file type.

<input type="file" name="image" accept=".jpg, .png,.jpeg" id="file" class="custom-file-input" />

When i upload png image then only issue occurs with message Please enter a value with a valid extension.

In controller below is the code for validation of image.

$validator = Validator::make($request->all(), [
                'image' => 'mimes:jpeg,bmp,png|max:4000',
            ]);

3 Answers 3

2

Hello i have resolved the issue and the problem was space between accept types

code with bug is as below

<input type="file" name="image" accept=".jpg, .png,.jpeg" id="file" class="custom-file-input" />

After resolving bug (in accept there is space after .jpg, .png) so removed it.

<input type="file" name="image" accept=".jpg,.png,.jpeg" id="file" class="custom-file-input" />
Sign up to request clarification or add additional context in comments.

1 Comment

thanks. I initially used accept="image/*" and it keeps getting the error until i tried your solution
0

You have not completed the requirements for the mimetypes rule:

https://laravel.com/docs/5.6/validation#rule-mimetypes

'image' => 'mimetypes:image/jpeg,image/png,image|max:4000',

You should use the mimes rule as shown in the docs

'image' => 'mimes:jpeg,png|max:4000',

3 Comments

Still getting error Please enter a value with a valid extension. no luck
It shows error message from jquery.validate.min.js js script
have a look at this: github.com/jquery-validation/jquery-validation/issues/1258 . Try jzaefferer suggestion of using the extension method
0

Without the complete code, it won't be easy for anyone to tell you exactly what can be the error or problem.

I assume you are using a form to submit the file and you might have missed enctype="multipart/form-data" on the form tag.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.