I have a form that after save shows the upload controls and I use ‘JSON.stringify(myObject)’ to generate a JSON object to pass to uploadifive so my upload.php file can create a db record, this resolves to {‘record_type’:‘project’,‘id’:“1”}.
php is reporting an undefined index for ‘record_type’ and ‘id’, the file itself uploads successfully. how do I pass the variable to uploadifive and execute it correctly so PHP can get access to the index values.
For those that may be thinking PHP cannot read json natively, the plugin is suppose to convert JSON to a $_POST array.
$(document).ready(function () {
....... //some other code
.......
$(function(myUploadFormData){
$('#file_input').uploadifive({
'auto' : false,
'multi' : false,
'buttonClass' : 'button',
'formData' : myUploadFormData,
'buttonText' : 'Select',
'uploadLimit' : 1,
'queueID' : 'droplist',
'width' : 75,
'height' : "25px",
'queueSizeLimit' : 1,
'uploadScript' : 'php/upload.php',
'onUploadComplete' : function(file, data) { console.log(data); }
});
});
$("#file_upload").on("click", function() {
$("#file_input").uploadifive('upload');
});
});
function uploadFormData(id, record_type){
var myObject = new Object();
myObject.record_type = record_type;
myObject.id = id;
var myUploadFormData = JSON.stringify(myObject);
}