There are a lot of questions about file upload with Android but most of them without answer and actually none of them are related with javascript or php. I'm seeing strange behaviour when selecting a file to upload on Android (4.4.4) native browser (HTC One_M8) and what it gives me is this;
C:\fakepath\image:12045
"Fakepath" part doesnt bother me, what bothers me is that I cant get file name out of /input type="file"/ html tag. I'm sending files with $.ajax and it works on Chrome, FF, Safari (desktop & iPhone), It works also on my M8 with Chrome, but not with native browser.
This is what I use to get selected files;
var filedata = document.getElementById("userFile");
formdata = false;
if (window.FormData) {
formdata = new FormData();
}
var i = 0, len = filedata.files.length, img, reader, file;
for (; i < len; i++) {
file = filedata.files[i];
if (window.FileReader) {
reader = new FileReader();
reader.onloadend = function(e) {
// showUploadedItem(e.target.result, file.fileName);
};
reader.readAsDataURL(file);
}
if (formdata) {
formdata.append("userFile[]", file);
}
}
And this is how I send them to handle.php
$.ajax({
url: 'handle.php',
type: 'POST',
xhr: function() {
var myXhr = $.ajaxSettings.xhr();
if(myXhr.upload){
}
return myXhr;
},
data: formdata,
dataType:'json',
cache: false,
contentType: false,
processData: false,
beforeSend: function(xhr, opt) {
$('#control-console').append($('input[type=file]').val());
$('input[type=file]').val("");
},
success: function() {
},
complete: function(podatki) {
$('#control-console').append(podatki.responseJSON.name);
console.log(podatki)
$.each(podatki.responseJSON.name, function(i, val) {
console.log(val);
insertFrame(val);
});
processing = false;
}
});
I haven't found any documentation about this so I don't really know if this is a bug in Android native browser or do I have to use different approach.
Has anyone faced the same problem and maybe found a solution ?