javascript - File not received at server using FormData
I'm uploading a form containing a file to my server, which runs validation and returns success or failure.
The form is sent using Ajax and FormData.
On my test server all data, including the file is received. However, on my live server it returns saying that this file is missing.
If i interrogate the FormData object in both environments the file is present, it just never seems to make it to the server.
Obviously i've removed a couple of items and replaced with *s and also the post url is generated by the page.
HTML:
Javascript:
$('form').submit( function( e ) {
formData = new FormData( this );
$.ajax({
xhr: function() {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("progress", function(evt) {
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
percentComplete = parseInt(percentComplete * 100);
percentShown = percentComplete*0.98;
showProgress(percentShown);
}
}, false);
return xhr;
},
url: '{{Request::url()}}/process',
type: 'POST',
data: formData,
processData: false,
contentType: false
}).done(function(data) {
if (data[0] == 0) {
console.log( data[1][0] );
console.log( data[2] );
$('#feedback').html(data[1][0]).removeClass("hidden");
$('#key_video').removeClass("hidden");
$("#uploading_feedback").addClass("hidden");
$(".progress").addClass("hidden");
}
else if (data[0] == 1) {
window.location.assign(data[1]);
}
});
e.preventDefault();
});
Answer
Solution:
If your code is working on test server then just check folder permission and folder location. permission should be 777.
Thanks