1

Hi I have one requirement where I am expecting a lot of video upload traffic but I want to make sure the uploaded file only are videos.

I have not used any uploader plugin for some specific reason.

<input type="file" id="upload" class="btn btn-blue" style="height: 35px;" name="file" /><br />

I am using simple html file type input and I want to restrict only video upload.

I have tried checking extensions but It's lot of extension and difficult to check each one of it.

http://www.fileinfo.com/filetypes/video

Any idea on this?

3
  • you can do the following : when the user clicks the submit button to upload the video,Use jQuery to determine the file extension i.e allow the file to be uploaded only if the file extension is .mp4 or .avi etc... if not then use event.preventdefault() followed by a message that only video files should be uploaded Commented Oct 31, 2014 at 4:25
  • to check with I guess 150 + video extensions are not a good way to restrict. Commented Oct 31, 2014 at 4:29
  • then try some regular expression in the process i have mentioned maybe that will help Commented Oct 31, 2014 at 4:30

1 Answer 1

1

There is no way you can restrict the upload on client side. You should be using server side validation for doing such validations.

You can set the accept attribute as video for input type file. this only show the file-type filtering based on MIME type for the file-select which can be changed by user :

<input type="file" accept="video/*">

for setting through JS:

document.getElementById("upload").accept = "video/*";
Sign up to request clarification or add additional context in comments.

2 Comments

Notice: accept video/* attribute is valid from HTML5 developer.mozilla.org/en-US/docs/Web/HTML/Element/Input means that still in 2014 IE8,9 are to take in serious consideration.
If I use accept attribute it will not restrict me. In browse window I can select all files and select any non video file.

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.