移动端头像上传

头像上传HTML代码:

<form  action="/index.php?m=&c=User&a=uploadImage" method="post" id="formid" enctype= "multipart/form-data" style="display: block;">
        <input id="upfiles" class="upfiles" type="file" name="log" onchange="uploadOperate();">
        <a class="pic-img">
            <img class="showimg" width="100px" onclick="" src="">
        </a>
        <input type="submit" value="提交" class="btn2">
</form>

 

上传之后显示当前头像:

   $("#upfiles").change(function(){
        var objUrl = getObjectURL(this.files[0]) ;
        if (objUrl) {
            $(".showimg").attr("src", objUrl);
        }
    })

    function getObjectURL(file) {
        var url = null;
        if (window.createObjectURL != undefined) { // basic
            url = window.createObjectURL(file);
        } else if (window.URL != undefined) { // mozilla(firefox)
            url = window.URL.createObjectURL(file);
        } else if (window.webkitURL != undefined) { // webkit or chrome
            url = window.webkitURL.createObjectURL(file);
        }
        return url;
    }

  

posted on 2016-05-10 17:05  菜鸟丫丫  阅读(458)  评论(0编辑  收藏  举报

导航