通过WordPress中的jquery ajax跨浏览器文件上传器

i am trying to use jquery.upload v1.0.3 found in: https://github.com/bassjobsen/jqueryupload

below is the js code:

fileChange = function(id,element,pos){
        $(id).upload(baseUrl+'/library/includes/plugins/fileupload/inc/upload.php', function(data) {
            alert(data.filename);
        }, 'json');
    }

below is the php code:

if (move_uploaded_file($_FILES['file']['tmp_name'], '../../../../../../../uploads/'. $_FILES['file']['name'])) {
    $data = array('filename' => $_FILES['file']['name']);
} else {
    $data = array('filename' => 'Failed to save');
}

header('Content-type: text/html');
echo json_encode($data);

the above works great on firefox, google, safari and mobile devices. however it breaks if i try to use it on ie. so far i have tested on ie9 and ie10 and i keep getting the error below:

unable to get value of the property 'filename': object is null or undefined

i am under the impression that this plugin should work on ie6+ but i have no idea, i just need this to work ie8+

i been scratching my head for hours so any help is greatly appreciated.

just an update, my html has input file as hidden via inline style which actions the fileChange function onchange. i also have another visible button which triggers a click event on the input file.

douxieshang5577
douxieshang5577 如果IE不工作,那么它必须以不同的方式发布-看看var_export($_POST,true)来看看有什么不同......
5 年多之前 回复
donglijuan8227
donglijuan8227 说实话,我的实际PHP代码是:require_once(ABSPATH。'wp-admin/includes/image.php');require_once(ABSPATH。'wp-admin/includes/file.php');require_once(ABSPATH。'wp-admin/includes/media.php');$aid=media_handle_upload('file',0);我只是使用上面的例子进行测试。我知道路径是正确的,因为如果我使用其他浏览器上传,它工作正常
5 年多之前 回复
doutuan9357
doutuan9357 为什么不使用完整路径而不是../../../../../../../uploads/?!
5 年多之前 回复

1个回答

just to confirm, the file uploader found in https://github.com/bassjobsen/jqueryupload does work on ie.

the php code that i posted also works fine.

the javascript code that i posted also works fine.

the problem was, IE < than version 11 does not behave well when you use a separate styled button to open the input file indirectly.

i have fixed the issue by removing the separate styled button and now i am accessing the input file directly. however this means my browse button does not look consistent on all browsers

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐