Zenel Shabani Zenel Shabani - 1 year ago 91
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:

url: '/upload/create',
type: 'POST',
dataType: 'json',
data: JSON.stringify(data),
success: function(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 Source

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,
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download