i am using jquery fileupload and i want to pass the input name of the file in the formData and everything i have try fails.
I try to use this.name but its seems that i dont have access of this in the formData
formData : { action:'upload', field:this.name , extensions : 'gif|jpeg|jpg|png'}
I have try to use data attributes but i dont get any post in that case
<input id="input-image2" class="file-upload" type="file" name="image2"
data-form-data='{ action:'upload', field:image2 , extensions : 'gif|jpeg|jpg|png'}'
>
Does anyone know how to add the input name (in this case image2) to formData?
The fileupload init as follows
and i need to fill the field param of formData with the name of the input file which is image2
$('.file-upload').fileupload({
url: '/myfile.php',
formData : { action:'upload', field:this.name , extensions : 'gif|jpeg|jpg|png'},
acceptFileTypes: /(\.|\/)(gif|jpeg|jpg|png)$/i,
add : function (e, data) {
var type=data.files[0].type;
var size=data.files[0].size;
var name=data.files[0].name;
if(type=="image/gif" || type=="image/jpg" || type=="image/jpeg" || type=="image/png")
{
data.submit();
}
else
{
//data.submit();
alert('Please upload only .gif, .jpeg, .jpg .png files');
}
},
fail: function(e, data){
alert(data.jqXHR.responseText);
},
dataType: 'json',
done: function (e, data)
{
//code here
},
progressall: function (e, data)
{
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#progress .progress-bar').css(
'width',
progress + '%'
);
}
}).prop('disabled', !$.support.fileInput)
.parent().addClass($.support.fileInput ? undefined : 'disabled');
Any help appriciated. Thanks