I'm working on a website similar to YouTube but for my company. What I want to do is making possible for users to upload photos and videos by themselves (instead of asking me everytime).
I got issues with the video upload part, I used the same technique for the photo upload and it worked just fine !
Here is my code:
$(function () {
$('#my_form').on('submit', function (e) {
e.preventDefault();
var $form = $(this);
var formdata = (window.FormData) ? new FormData($form[0]) : null;
var data = (formdata !== null) ? formdata : $form.serialize();
$.ajax({
url: 'MgtImportVideo.php',
type: 'POST',
contentType: false,
processData: false,
dataType: 'html',
data: data, //data = serialized form
xhr: function(){
//do stuff like showing percentage progress
},
beforeSend : function (){
//do some stuff like incrementing variables
},
success: function (response) {
//do other stuff like diplaying error/sucess messages
}
});
});
I put contentType
and processData
to false because I heard it was required for the upload.
And the actual video file is stored like this :
$('#my_form').find('input[name="fileVideo[]"]').on('change', function (e) {
var files = $(this)[0].files;
var urivideo=false;
urivideo=window.URL.createObjectURL(files[0]);
//Then do some other stuff (I guess not really important here)
});
Then in my MgtImportVideo.php
file, the $_POST and $_FILES are not getting any data and showing as empty arrays.
Can someone help me figuring this out ?