Android的文件上传 - 错误的文件名,本机浏览器本机、文件名、文件上传、浏览器

由网友(七夏)分享简介:有很多关于与Android文件上传的问题,但他们大多没有答案,实际上他们没有与JavaScript或PHP相关。选择一个文件,在Android上载,当我看到奇怪的行为(4.4.4)原生浏览器(HTC One_M8)以及它给我就是这个; There are a lot of questions about file u...

有很多关于与Android文件上传的问题,但他们大多没有答案,实际上他们没有与JavaScript或PHP相关。选择一个文件,在Android上载,当我看到奇怪的行为(4.4.4)原生浏览器(HTC One_M8)以及它给我就是这个;

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 图片:12045

Fakepath部分犯规打扰我,让我困扰的是,我不能让文件名输出/输入类型=文件/ HTML标签。我送文件,$就和它的作品在Chrome,FF,Safari浏览器(桌​​面和放大器; iPhone),它的工作原理还对我的M8与浏览器,但不与本地浏览器。

"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);
    }
}

这是我送他们到handle.php

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;

        }
    });

我还没有发现这方面有任何文件,所以我真的不知道,如果这是Android原生浏览器中的错误或做我必须使用不同的方法。

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 ?

推荐答案

我在最后几个小时已经研究时所上传的文件是为画廊的android手机中,由于安全检查上述问题发生。没有文件名,扩展名,大小将是可读的。

What I have researched in last few hours is when file being uploaded is within the gallery for the android phone, due to security checks above problem happens. No file name, extension, size will be readable.

要解决此:1-点击浏览按钮,你将被带到你的设备的画廊。2 - 在画廊点击选项图像(...),并启用内部存储的右上角。3-确定你上传的文件是内部存储。4-访问内部存储选项上载。5文件应显示正确的名称。

To workaround this: 1- Click on browse button, you will be taken to gallery of your device. 2- On right corner of gallery click Options image ("...") and Enable "Internal Storage". 3- Make sure the file you upload is in Internal Storage. 4- Access "Internal Storage" option while uploading. 5- File should show the correct name.

阅读全文

相关推荐

最新文章