0

I want to validate the files to upload only in video formats like mp4 or mkv files only, I want to make sure the user is uploading video no anything else using ajax I want valid the FileInput is video not anything else, and if this file not video then show alert in error

<div class="form-group">
                            <label for="" class="control-label"><b>Upload Video</b></label>
                            <input type="file" class="form-control form-control-sm" name="vid" onchange="displayVID(this,$(this))">
                        </div>



function displayVID(input,_this) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();
            reader.onload = function (e) {
                $('#vid-field').html("<source src='"+e.target.result+"'>");
                console.log(e.target.result)
            }

            reader.readAsDataURL(input.files[0]);
        }
    }
    function displayImg(input,_this) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();
            reader.onload = function (e) {
                $('#vid-field').attr('poster', e.target.result);
            }

            reader.readAsDataURL(input.files[0]);
        }
    }
$('#manage-upload').submit(function(e){
        e.preventDefault()
        start_load()
        $.ajax({
            url:'ajax.php?action=save_upload',
            data: new FormData($(this)[0]),
            cache: false,
            contentType: false,
            processData: false,
            method: 'POST',
            type: 'POST',
            success:function(resp){
                if(resp == 1){
                    alert_toast('<i class="fa fa-check text-white"></i> Video successfully Upload.',"success");
                    setTimeout(function(){
                        location.reload()
                    },750)
                }
            }
        })
    })
  • Please see [this SO question](https://stackoverflow.com/questions/310714/how-to-check-file-types-of-uploaded-files-in-php). – FiddlingAway Jan 03 '23 at 11:16

0 Answers0