zoukankan      html  css  js  c++  java
  • JS 读取本地文件转base64 上传到服务器

    $("#qrcode").on("change", function(){
      var bs64 = base64(document.getElementById("qrcode"));
    });
    // 商品评价 图片转base64
    // Process the file
    // Precondition: expects image files, but works with others too
    function base64(file) {
        var reader = new FileReader();
        var pos = file.target.files[0].name.lastIndexOf(".");
        var type = file.target.files[0].name.substring(pos + 1);
    
        if (type.toLowerCase() != "png" && type.toLowerCase() != 'jpg' && type.toLowerCase() != 'jpeg' && type.toLowerCase() != 'gif' && type.toLowerCase() != 'bmp') {
            alert("格式错误,请上传'png、jpg、jpeg、bmp、gif'格式文件");
            return;
        }
        num += 1;
        reader.onloadend = (
            function(e) {
                imgurl = e.target.result;
                updateBackground();
            }
        );
    
        // Read the file
        reader.readAsDataURL(file.target.files[0]);
    }
    
    
    // Return the data to the user
    function updateBackground(){
      // urlElement.innerHTML = imgurl;
       
      jq.ajax({
        url:'user.php',
        data:{
          act:'update_pic',
          imgurl:imgurl
        },
        type:'post',
        dataType:'text',
        success:function(data){
          if(data == "error"){
            alert("上传失败,请重新操作");
          }else{
            jq("#comment_image").prepend("<input type='hidden' name='images[]' value='"+data+"'>");
            jq("#comment_image").prepend("<img width='70' height='70' src='"+imgurl+"' style='margin: 2px;'>");
            num-=1;
           sum+=1;
          }   
        }
      })
    
    }
  • 相关阅读:
    CMDB 理论
    分布式
    闲着无聊 一个python的,三级菜单。装逼版。
    献上一段,派遣网易云音乐,音频的代码。
    redis 安装
    selenium之 chromedriver与chrome版本映射表(更新至v2.46)
    简单的爬虫
    anaconda使用方法
    crm开发之用户重置密码
    模块和包,logging模块
  • 原文地址:https://www.cnblogs.com/jh1994/p/5660775.html
Copyright © 2011-2022 走看看