上傳圖片-簡易

來源:互聯網
上載者:User

標籤:提示   php   control   att   img   pos   rem   cache   site   

                                    <div class="col-sm-3">                                        <div class="imguploadbox">                                                <label for="imgUpload">                                                <input type="file" id="imgUpload" accept=".png,.jpg" style="display: none">                                            </label>                                            <div class="addimg">                                                <?php if($model->thumb): ?>                                                    <img src="<?= $model->thumb ?>_120X120.png" class="img-circle" id="user_img"">                                                <?php endif; ?>                                            </div>                                        </div>                                    </div>                                    <div class="col-sm-9">                                        <div class="editavatarcontrol" style="margin-left:25px;">                                            <p>支援格式:JPEG / PNG 512X512, < 1MB</p>                                            <button type="button" class="btn btn-avatar" id="image-change-btn">修改圖片</button>                                        </div>                                    </div>

  

  $(‘#imgUpload‘).on(‘change‘,function(){            imgUpload();    });    function imgUpload(){        var formdata = new FormData();        formdata.append(‘UploadForm[imageFile]‘,$(‘#imgUpload‘)[0].files[0]);        $.ajax({            url:‘/site/upload‘,            type: ‘post‘,            cache:false,            data: formdata,            processData:false,            contentType:false,            success:function(data){                if(data === ‘error‘){                    $.confirm({                        title : ‘提示‘,                        content : ‘圖片大小格式不符,請選擇合適圖片‘,                        buttons : {                            confirm : {                                text : ‘確認‘                            }                        }                    })                }else{                var tempImg = $(‘<img/>‘);                tempImg.attr(‘src‘,data+‘_120X120.png‘);                tempImg.attr(‘width‘,‘120‘);                tempImg.attr(‘height‘,‘120‘);                $(‘#user_img‘).remove();                $(‘.addimg‘).empty().append(tempImg);                window.location.reload();                }            },            error:function(e){                $.confirm({                    title: ‘提示‘,                    content: ‘頭像上傳遇到錯誤,請檢查圖片‘,                    buttons: {                        confirm: {                            text: ‘確認‘                        }                    }                })            }        })    }    $(‘#image-change-btn‘).click(function(){        $(‘#imgUpload‘).click();    })

  

上傳圖片-簡易

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.