thinkphp5Ôõô¼ÓlayuiʵÏÖͼƬÉÏ´«¹¦Ð§
ÍøÕ¾ÖÐÐí¶à±íµ¥¶¼»áÓõ½ÉÏ´«Í¼Æ¬£¬logo£¬ÕÕƬ£¬Óû§Ò²»áÉÏ´«Í¼Æ¬£¬Õâ¸öʱ¼äÍøÕ¾¾ÍÐèÒªÒ»¸öÉÏ´«Í¼Æ¬µÄ¹¦Ð§£¬²¢ÇÒÔÚÉÏ´«ºóÏ£ÍûÄÜÔ¤ÀÀһϿ´ÉÏ´«µÄ¶Ô²î³Ø¡£
thinkphp5¼ÓlayuiʵÏÖͼƬÉÏ´«¹¦Ð§£¨´øͼƬԤÀÀ£©Ë¼Ð÷£¬Òì²½´«ÊäͼƬ²¢Ô¤ÀÀ£¬½«Òì²½ÉÏ´«ºóµÄÖµ·µ»Ø±íµ¥Òþ²ØÓòÔÙÌá½»¡£
1¡¢ÒýÈëÎļþ
Ê×ÏÈ£¬ÒªÒýÈëjQueryÎļþ£¬ÕâÊDZØÐèµÄ
<link rel="stylesheet" type="text/css" href="__STATIC__/plugins/layui/css/layui.css" rel="external nofollow" > <script type="text/javascript" src="__STATIC__/plugins/layui/layui.js"></script>
µÇ¼ºó¸´ÖÆ
2¡¢HTML²¿·Ö
<form class="layui-form"> <div class="layui-input-inline"> <button class="layui-btn layui-btn-sm" onclick="return false;" id="upload_img"><i class="layui-icon"></i>ÉÏ´«Í¼Æ¬</button> @@##@@ /> <input type="hidden" name="img" value="{$data.item.img}"> </div> <div class="layui-form-item"> <div class="layui-input-block"> <button class="layui-btn" onclick="save()">ÉúÑÄ</button> </div> </div> </form>
µÇ¼ºó¸´ÖÆ
3¡¢¹¦Ð§ÊµÏÖ
<script type="text/javascript"> layui.use(['form','layer','upload'],function(){ $ = layui.jquery; var form = layui.form; layer = layui.layer; var upload = layui.upload; //Ö´ÐÐʵÀý var uploadInst = upload.render({ elem: '#upload_img' //°ó¶¨ÔªËØ ,url: '/admins.php/admins/video/upload_img' //ÉÏ´«½Ó¿Ú ,accept:'images' ,done: function(res){ //ÉÏ´«Íê±Ï»Øµ÷ $('#pre_img').attr('src',res.msg); $('input[name="img"]').val(res.msg); } ,error: function(){ //ÇëÇóÒì³£»Øµ÷ } }); }); // ÉúÑÄ function save(){ var title = $.trim($('input[name="title"]').val()); var url = $.trim($('input[name="url"]').val()); if(title == ''){ layer.msg('ÇëÊäÈëӰƬÃû³Æ',{'icon':2,'anim':6}); return; } if(url == ''){ layer.msg('ÇëÊäÈëӰƬµØµã',{'icon':2,'anim':6}); return; } $.post('/admins.php/admins/video/save',$('form').serialize(),function(res){ if(res.code>0){ layer.msg(res.msg,{'icon':2,'anim':2}); }else{ layer.msg(res.msg,{'icon':1}); setTimeout(function(){parent.window.location.reload();},1000); } },'json'); } </script>
µÇ¼ºó¸´ÖÆ
4¡¢ºǫ́´¦Àí
ͼƬÉÏ´«
public function upload_img(){ $file = request()->file('file'); if($file==null){ exit(json_encode(array('code'=>1,'msg'=>'ûÓÐÎļþÉÏ´«'))); } $info = $file->move(ROOT_PATH.'public'.DS.'uploads'); $ext = ($info->getExtension()); if(!in_array($ext,array('jpg','jpeg','gif','png'))){ exit(json_encode(array('code'=>1,'msg'=>'ÎļþÃûÌò»Ö§³Ö'))); } $img = '/uploads/'.$info->getSaveName(); exit(json_encode(array('code'=>0,'msg'=>$img))); }
µÇ¼ºó¸´ÖÆ
ÉúÑÄÄÚÈÝ
public function save(){ $id = (int)input('post.id'); $data['title'] = trim(input('post.title')); $data['channel_id'] = (int)input('post.channel_id'); $data['charge_id'] = (int)input('post.charge_id'); $data['area_id'] = (int)input('post.area_id'); $data['img'] = trim(input('post.img')); $data['url'] = trim(input('post.url')); $data['keywords'] = trim(input('post.keywords')); $data['desc'] = trim(input('post.desc')); $data['status'] = (int)input('post.status'); if($data['title'] == ''){ exit(json_encode(array('code'=>1,'msg'=>'ӰƬÃû³Æ²»¿ÉΪ¿Õ'))); } if($data['url'] == ''){ exit(json_encode(array('code'=>1,'msg'=>'ӰƬµØµã²»¿ÉΪ¿Õ'))); } if($id){ $this->db->table('video')->where(array('id'=>$id))->update($data); }else{ $data['add_time'] = time(); $this->db->table('video')->insert($data); } exit(json_encode(array('code'=>0,'msg'=>'ÉúÑÄÀÖ³É'))); }
µÇ¼ºó¸´ÖÆ
ÒÔÉϾÍÊÇthinkphp5Ôõô¼ÓlayuiʵÏÖͼƬÉÏ´«¹¦Ð§µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡
ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是博ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是博ʵʱÐÞÕý»òɾ³ý¡£