Any workarounds for the Safari HTML5 multiple file upload bug?

后端 未结 3 1363
执笔经年
执笔经年 2021-01-18 11:24

After weeks of tweaking I finally gave up. I just couldn\'t fix my multiple file upload on safari, which really bothered me because my code worked perfectly as it should on

3条回答
  •  醉梦人生
    2021-01-18 12:08

    This is oldish question, but ... hack-type workaround is below.

    Just remove multiple attribute for Safari, turnig it into MSIE<=9 little brother (non-XHR).

    Rest of browsers will not be affected.

    When Safari finally fixes problem, all you have to do is remove this hack::code and go back to standard input code.

    here is standard input sample:

    
    

    jQuery solution:

    Just place it somewhere on a page, where you have files input tag.

    you may read more here: How to detect Safari, Chrome, IE, Firefox and Opera browser?

    $(document).ready(function () { 
        if (Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor')>0);
             $('.fileupload-input').removeAttr("multiple");
    });
    

    PHP solution

    you will need some code to id browser I used a class I got one in github (MIT) get it here: https://github.com/gavroche/php-browser

     $files = '';
     if (Browser::getBrowser() === Browser::SAFARI) {
        $files = '';
     }
    echo $files
    

    That is all.

提交回复
热议问题