Nana-Odai's avatar

how to validate images, videos, audios, pdfs, word, excell, and powerpoint documents all from one input file

i want to validate every uploaded file. That is images, videos, audios, pdfs, word, excell, and powerpoint documents all from one input file but getting below error

The file must be a file of type: jpeg, png, PNG, jpg, zip, pdf, ppt, pptx, xlx, xlsx, docx, doc, gif, webm, mp4, mpeg.

This is the validation

'file' => 'required|mimes:jpeg,png,jpg,zip,pdf,ppt, pptx, xlx, xlsx,docx,doc,gif,webm,mp4,mpeg',

0 likes
12 replies
ajithlal's avatar

in your form add enctype. <form id="video-work-upload-form" action="" method="POST" class="" role="form" enctype="multipart/form-data">.

Nana-Odai's avatar

i have tried your solution but not working. what does video-work-upload-form mean or do?

jlzandrad's avatar

there is also something to do with the way your server is setup, I remember having to change the server settings when validating MS project manager files, so if you are trying to validate a mine type that is not common you may need to take a look on the server.

http://www.htaccess-guide.com/adding-mime-types/

Nana-Odai's avatar

if i upload any file it fails. but the mime is listed in the validation

Maria30's avatar

@nana You should include file in your validation rules :

'file' => 'required|file|mimes:jpeg,png,jpg,zip,pdf,ppt, pptx, xlx, xlsx,docx,doc,gif,webm,mp4,mpeg',

Documentation: file. The field under validation must be a successfully uploaded file. https://laravel.com/docs/5.8/validation#rule-file

enctype="multipart/form-data" is also important to exist in your form as @ajithlal mentioned, and also fix the spaces between mime types as @sergiu17 said.

1 like
Sergiu17's avatar

@nana-odai you have space betweenppt, and pptx or space between pptx, and xlx - this may cause this issue you have

Nana-Odai's avatar

I am now getting this error when i upload a any file

The file must be a file.

The file must be a file of type: jpeg, png, jpg, zip, pdf, ppt, pptx, xlx, xlsx, docx, doc, gif, webm, mp4, mpeg.

I am getting below error also if i make the validation only required when on production server. ie 'file' => 'required' Unable to guess the MIME type as no guessers are available (have you enable the php_fileinfo extension?).

Maria30's avatar

@nana-odai test it by using only images

'file' => 'required|image|mimes:jpeg,png,jpg' .

If it works this way, you may have to create custom rule for this input.

1 like
Maria30's avatar

And your form should include enctype="multipart/form-data" like this:

 <form method="POST" action="/test" enctype="multipart/form-data">
  @csrf
  <div class="form-group">
    <label for="file">Upload a file</label>
    <input name="file" type="file" class="form-control">
  </div>

   <button type="submit" class="btn btn-primary mb-2">Submit</button>
</form>
1 like
Nana-Odai's avatar

Still gives error, i don't know what am doing wrong

Maria30's avatar

You can't get help if you don't show the code you are using and the errors you get

Please or to participate in this conversation.