精品项目开发
分享
  • 收藏
  • 举报
    X
    记录:图片ajax上传算是可以了,不过这个上传地址,哪位大神有空指教一下
    394
    6

    代码来自官方

    uiUpload.add({
      quality:1,
               onSuccess: function(file){
                   this.toBase64({
                       onSuccess: function (url) {
                        $("#btnUpload").find('.span1').text('重新上传');
                        upload_pic(url);
                       }
                   });
               }
           })
    
    function upload_pic(base64){
              var image = new Image();
              image.src = base64;
              image.onload = function() {
                var resized = resizeUpImages(image);
                var severUrl = "/index.php/index/attachment/upload/dir/images/from/base64/module/bbs.html";
                $.post(severUrl, {'imgBase64':resized,'Orientation':'','tags':''}).done(function (res) {
                  if(res.code==1){
                    //console.log(res);
                    var url = res.path;
                    if(url.indexOf('://')==-1 && url.indexOf('/public/')==-1){
                      url = '/public/'+url;
                    }
    $(".uselimg").html('');
    $(".uqrcode").val(url);
    console.log(url)
                  }else{
                    alert(res.info);
                  }
                }).fail(function () {
                  alert('操作失败,请跟技术联系');
                });
              }
            }
    
            function resizeUpImages(img) {
              //压缩的大小
              var max_width = 1920; 
              var max_height = 1080; 
              var canvas = document.createElement('canvas');
              var width = img.width;
              var height = img.height;
              if(width > height) {
                if(width > max_width) {
                  height = Math.round(height *= max_width / width);
                  width = max_width;
                }
    
              }else{
                if(height > max_height) {
                  width = Math.round(width *= max_height / height);
                  height = max_height;
                }
              }
              canvas.width = width;
              canvas.height = height;
              var ctx = canvas.getContext("2d");
              ctx.drawImage(img, 0, 0, width, height);
              //压缩率
              return canvas.toDataURL("image/jpeg",0.72); 
            }

    请教一下:其中

    var severUrl = "/index.php/index/attachment/upload/dir/images/from/base64/module/bbs.html";

    这个地址有什么规律吗?或者说在有需要上传图片的页面,怎么找到图片的上传地址呢?感谢各位!

    0
    赏礼
    赏钱
    收藏
    点击回复
        全部留言
    • 6
    • Suifeng 程序开发者 消费:23.24元 2020-07-08 08:46 08:466楼
      dir/images 中的 images 为上传到哪个目录 module/bbs 中的bbs 是属于哪个模块 暂时用处不大
      from/base64 中的base64是以base64位上传
      wr1688 消费:2593.25元 华为 2020-07-08 09:12
      谢谢风神
      wr1688 消费:2593.25元 华为 2020-07-08 09:13
      @wr1688 bbs改任意频道也可以吗
      Suifeng 消费:23.24元 2020-07-08 09:14
      @wr1688 可以
    0 赏钱 赏礼回复
    • admin 超级管理员 消费:3.04元 2020-07-08 06:08 06:08
      其他手机
      6楼
      这个地址可以固定,没太大区别
      wr1688 消费:2593.25元 华为 2020-07-08 07:21
      好的,感谢老大
    0 赏钱 赏礼回复
    更多回复
        你可能感兴趣的主题
    恢复多功能编辑器
  • 3 1
  • 精品项目开发
        圈内贴子3655
    • 圈子成员219
    本圈子内的新贴

    推荐内容
    扫一扫访问手机版
    请选择要切换的马甲:

     
    网页即时交流
    QQ咨询
    咨询热线
    020-28998648