zoukankan      html  css  js  c++  java
  • 关于jq上传头像二进制的形式上传

    html代码如下

    <img class="sss" src="" style="border-radius:50%;150px;height: 150px; display: none"/>
    <input name="image2" type="file" value="" />
    <input type="hidden" value="" name="image"  />
    jq代码如下

    <script>
    $("input[type='file']").change(function () {
    if(typeof this.files == "undefined"){
    return "";
    }
    var img=this.files[0];
    var type=img.type;
    var url=getObjectURL(img);
    if(type.substr(0,5) != 'image' ){
    alert("非图片");
    return;
    }
    function getObjectURL(file) {
    var url = null;
    if (window.createObjectURL != undefined) {
    url = window.createObjectURL(file)
    } else if (window.URL != undefined) {
    url = window.URL.createObjectURL(file)
    } else if (window.webkitURL != undefined) {
    url = window.webkitURL.createObjectURL(file)
    }
    return url
    };

    var reader = new FileReader();
    reader.onload = function(e) { //编码文件
    var head = e.currentTarget.result;
    $("input[name='image']").val(head);
    $(".sss").show();
    };
    reader.readAsDataURL(this.files[0]);

    $(".sss").attr("src",url);
    });
    </script>

    将图片以二进制的方式上传上去,减少了服务器的内存
    
    
  • 相关阅读:
    POJ1034 The dog task
    POJ1033 Defragment
    POJ1032 Parliament
    POJ1031 Fence
    POJ1030 Rating
    POJ1029 False coin
    伪元素的使用
    伪元素选择器:before 以及 :after
    jquery html() 和text()的用法
    用CSS绘制三角形
  • 原文地址:https://www.cnblogs.com/jhcyzxx/p/6693422.html
Copyright © 2011-2022 走看看