尊龙凯时人生就是博

ThinkphpÔõôÍŽáajaxFileUploadʵÏÖajaxÒ첽ͼƬ´«Êä

1¡¢ÒýÓÃÎļþ

ÏÈÒýÈëjqueryÓëajaxfileupload²å¼þ¡£×¢ÖØÏȺó˳Ðò£¬Õâ¸ö²»±Ø˵ÁË£¬ËùÓеIJå¼þ¶¼ÊÇÕâÑù¡£

<script src="__ADMIN__/js/jquery.min.js?v=2.1.4"></script>
<script src="__ADMIN__/js/ajaxfileupload.js"></script>

µÇ¼ºó¸´ÖÆ

2¡¢HTML´úÂë

<div class="form-group">
    <label class="col-sm-2 control-label">ËõÂÔͼ</label>
    <div class="col-sm-8">             
        <div id="file-pretty">
            <div>
                <input type="file" id="file_thumb" name="thumb" class="form-control"  value="">
                <div class="input-append input-group">
                    <span class="input-group-btn">
                        <button id="btn_thumb" class="btn btn-white" type="button">Ñ¡ÔñͼƬ</button>
                    </span>
                    <input id="info_thumb" name="thumb" class="input-large form-control" type="text" value="{$info.img}">
                </div>
            </div>
        </div>                     
    </div>
    <div class="col-sm-2">@@##@@</div>
</div>

µÇ¼ºó¸´ÖÆ

3¡¢JS´úÂë

    <script type="text/javascript">
	    $(function(){
	        $("#btn_thumb").click(function(){
	            $("#file_thumb").click();
	        });

	        //Òì²½ÉÏ´«
	        $("body").delegate('#file_thumb', 'change', function(){
	            var filepath = $("input[name='thumb']").val();
	            var arr = filepath.split('.');
	            var ext = arr[arr.length-1];
	            //alert(filepath);exit();

	            if('gif|jpg|png|bmp'.indexOf(ext)>=0){
	                $.ajaxFileUpload({
	                  url: '/admin/slide/upload_image',
	                  secureurl: false,
	                  fileElementId: 'file_thumb', //file±êÇ©ID
	                  dataType: 'json', //·µ»ØÊý¾ÝÀàÐÍ
	                  data:{name:'thumb'},
	                  success:function (data,status){
	                      $("#info_thumb").val(data);
	                      $("#show_thumb").attr('src','/uploads/images/'+data);
	                      $("#info_thumb").focus();
	                  },
	                  complete:function (XMLHttpRequest){

	                  },
	                  error:function (data,status,e){
	                      layer.alert('ÉÏ´«Ê§°Ü!');
	                  },
	              });
	            } else {
	                //Çå¿Õfile
	                $("#file_thumb").val("");
	                layer.alert('ÇëÉÏ´«ºÏÊʵÄͼƬÀàÐÍ!');
	            }

	        });
	    });
    </script>

µÇ¼ºó¸´ÖÆ

4¡¢ºǫ́´¦Àí£¨PHP£©

    //µ¥Îļþ£¨°üÀ¨µ¥Îļþ£©Òì²½ÉÏ´«
    public function upload_image(){
        //ͼƬÉÏ´«
        $file = request()->file(input('name'));
        $info = $file->move(ROOT_PATH . 'public/uploads/images');
        if($info) {
            return json_encode($info->getSaveName());
        }
    }

µÇ¼ºó¸´ÖÆ

5¡¢Ç°Ì¨Å²ÓÃ

<div id="slideshow">
  <ul class="rslides" id="slider">
    {volist name="data" id="vo"}
    <li><a href="{$vo.url}" rel="external nofollow"  rel="bookmark" target="_blank"> @@##@@</a>
      <p class="slider-caption">{$vo.title}</p>
    </li>
    {/volist}
  </ul>
</div>

µÇ¼ºó¸´ÖÆ

ÒÔÉϾÍÊÇThinkphpÔõôÍŽáajaxFileUploadʵÏÖajaxÒ첽ͼƬ´«ÊäµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是博ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是博ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是博

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ