jquery 無重新整理上傳的小function

來源:互聯網
上載者:User

標籤:thinkphp   inpu   gif   hang   fileread   sub   post   get   file   

function zll_up(click_id,up_url,text_id,show_id){    this.create = function(){}    //當點擊指定元素時,建立iframe form input(file)等元素    $("#"+click_id).click(function(){        console.log(‘click‘);        $("body").append("<form action=‘"+up_url+"‘ method=‘post‘ enctype=‘multipart/form-data‘ target=‘iframe_"+click_id+"‘ style=‘display:none;‘ name=‘form_"+click_id+"‘ id=‘form_"+click_id+"‘><input type=‘file‘ name=‘tupian_"+click_id+"‘ id=‘tupian_"+click_id+"‘></form>");        $("body").append("<iframe style=‘display:none;‘ name=‘iframe_"+click_id+"‘ id=‘iframe_"+click_id+"‘></iframe>");                $(‘#tupian_‘+click_id).change(function(){            console.log(‘change‘);            var file = document.getElementById("tupian_"+click_id).files[0];            var reader = new FileReader();             reader.readAsDataURL(file);              reader.onload = function(evt){              $("#"+show_id).html(‘<img style="width:100%;height:100%;" src="‘ + evt.target.result + ‘" />‘);            }             $("#form_"+click_id).submit();        });                $("#iframe_"+click_id).on("load",function(){            console.log(‘load‘);            var data = $(window.frames[‘iframe_‘+click_id].document.body).find("textarea").html();            console.log(data);            $("#"+text_id).val(data);            //當上傳完成時刪除之前建立的元素            console.log(‘remove‘);            $("#iframe_"+click_id).remove();            $("#form_"+click_id).remove();        });                $("#tupian_"+click_id).click();    });}

js代碼

<div class="control-group">                        <label class="control-label item-label" >上傳圖片 (750*1525)<span class="check-tips"></span></label>                        <div class="controls uploadrow2" data-max="1" title="點擊修改圖片" rel="cover" id="upclick">                            <input type="hidden" name="img" id="img" value="{$art.img}">                            <div class="upload-img-box" rel="img" id="imgshow" style="height:auto;">                                <if condition="!empty($art[‘img‘])">                                    <img src="__UPLOADS__/{$art.img}"/>                                </if>                            </div>                        </div>                    </div>
<script type="text/javascript" src="引入上面的js代碼"></script>
<script type="text/javascript">
       zll_up("upclick","{:U("$con_name/z_upload")}","img","imgshow");
</script>

html代碼

function z_upload(){        //單檔案上傳        //公用上傳函數 zll 2017-6-7 11:35:44        //用於iframe的無重新整理上傳        $config = array(                ‘maxSize‘    =>    3145728,                ‘rootPath‘   =>    ‘./Uploads/‘,                ‘savePath‘   =>    ‘‘,                ‘saveName‘   =>    array(‘uniqid‘,‘‘),                ‘exts‘       =>    array(‘jpg‘, ‘gif‘, ‘png‘, ‘jpeg‘),                ‘autoSub‘    =>    true,                ‘subName‘    =>    array(‘date‘,‘Ymd‘),            );            $upload = new \Think\Upload($config);// 執行個體化上傳類            $info = $upload->upload();            if(!$info) {                // 上傳錯誤提示錯誤資訊                //    echo $upload->getError();                echo "<textarea>error</textarea>";            }else{// 上傳成功                echo "<textarea>".$info[array_keys($info)[0]][‘savepath‘].$info[array_keys($info)[0]][‘savename‘]."</textarea>";            }    }

PHP代碼(thinkphp3.2.3)

jquery 無重新整理上傳的小function

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.