javascript - File not received at server using FormData

130

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();
});
599

Answer

Solution:

If your code is working on test server then just check folder permission and folder location. permission should be 777.

Thanks

People are also looking for solutions to the problem: Facebook dilema; how to remove all members and add them back again, via PHP

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.