Zenel Shabani Zenel Shabani - 6 months ago 13
Javascript Question

Javascript sending array with files to php

So i'm sending a jquery object that contains some info about a file and the actual

$("#input").files[0]; item
.

The jquery/javascript looks something like the following:

$.ajax({
url: '/upload/create',
type: 'POST',
dataType: 'json',
data: JSON.stringify(data),
success: function(msg) {
alert(msg);
}
});


The data variable is a JQuery object that contains info about the uploaded file and the file itself(I think), I just passed it in the object.

Is there any way to extract and save this file on the server-side with PHP?

Answer

Just remove the JSON.stringify() call and you should be good. data should be an object, which gets converted to PHP's associative $_POST or $_GET array, stringify converts it to a string.

data: data,
Comments