• <legend id='cAbik'><style id='cAbik'><dir id='cAbik'><q id='cAbik'></q></dir></style></legend>
  • <i id='cAbik'><tr id='cAbik'><dt id='cAbik'><q id='cAbik'><span id='cAbik'><b id='cAbik'><form id='cAbik'><ins id='cAbik'></ins><ul id='cAbik'></ul><sub id='cAbik'></sub></form><legend id='cAbik'></legend><bdo id='cAbik'><pre id='cAbik'><center id='cAbik'></center></pre></bdo></b><th id='cAbik'></th></span></q></dt></tr></i><div id='cAbik'><tfoot id='cAbik'></tfoot><dl id='cAbik'><fieldset id='cAbik'></fieldset></dl></div>

      • <bdo id='cAbik'></bdo><ul id='cAbik'></ul>
      <tfoot id='cAbik'></tfoot>

        <small id='cAbik'></small><noframes id='cAbik'>

      1. layui实现上传图片并自定义截取(含php后端代码)

        时间:2024-07-12

        • <bdo id='CZQPJ'></bdo><ul id='CZQPJ'></ul>

              1. <tfoot id='CZQPJ'></tfoot>

                  <tbody id='CZQPJ'></tbody>
                  <i id='CZQPJ'><tr id='CZQPJ'><dt id='CZQPJ'><q id='CZQPJ'><span id='CZQPJ'><b id='CZQPJ'><form id='CZQPJ'><ins id='CZQPJ'></ins><ul id='CZQPJ'></ul><sub id='CZQPJ'></sub></form><legend id='CZQPJ'></legend><bdo id='CZQPJ'><pre id='CZQPJ'><center id='CZQPJ'></center></pre></bdo></b><th id='CZQPJ'></th></span></q></dt></tr></i><div id='CZQPJ'><tfoot id='CZQPJ'></tfoot><dl id='CZQPJ'><fieldset id='CZQPJ'></fieldset></dl></div>
                  <legend id='CZQPJ'><style id='CZQPJ'><dir id='CZQPJ'><q id='CZQPJ'></q></dir></style></legend>

                  <small id='CZQPJ'></small><noframes id='CZQPJ'>

                1. 支持Promise API
                  支持移动触摸事件
                  基于canvas技术,支持canvas的浏览器都可以使用该插件
                  通过Base64编码导出剪裁后的图片。 可以通过json数据来获取图片的位置和大小
                  可以通过json数据来设置图片的位置和大小
                  可以通过URL来获取图片。
                  HTML代码部分:
                  <script src="layui/layui/layui.js"></script>
                      <link rel="stylesheet" type="text/css" href="layui/layui/css/layui.css">
                      <link rel="stylesheet" type="text/css" href="cropper.css">
                      <script src="cropper.js"></script>
                      <script src="croppers.js"></script>
                  <div class="layui-form-item">
                      <label class="layui-form-label">头像</label>
                      <div class="layui-input-inline">
                          <input type="text" name="head" lay-verify="required" id="inputimgurl" placeholder="图片地址" class="layui-input">
                      </div>
                      <div class="layui-input-inline">
                          <div class="layui-upload-list" style="margin:0" id="srcimgurl"></div>
                      </div>
                      <div class="layui-input-inline layui-btn-container">
                          <button class="layui-btn layui-btn-primary" id="editimg">选择图片</button>
                      </div>
                      <div class="layui-form-mid layui-word-aux">头像的尺寸限定150x150px,大小在50kb以内</div>
                  </div>
                  layui组件调用
                  .use(['form', 'croppers'], function () {
                          var $ = layui.jquery
                              , form = layui.form
                              , croppers = layui.croppers
                              , layer = layui.layer;
                  
                          //创建上传组件
                          croppers.render({
                              elem: '#editimg'
                              , saveW: 150//保存宽度
                              , saveH: 150
                              , mark: 1 / 1 //选取比例
                              , area: ['90%', '80%']//弹窗宽度
                              , url: 'upload.php'
                              , done: function (res) {
                                  console.log(res.imgUrl)
                                  $("#inputimgurl").val(res.imgUrl);
                                  $("#srcimgurl").html('<img src="' + res.imgUrl + '" width="30" class="layui-upload-img">');
                              }
                          });
                      });
                  PHP后端上传
                  <?php
                  $upload_dir = 'upload';
                  $newDate = date("Y-m");
                  $imgUrl = $upload_dir . '/' . $newDate;
                  
                  if (!is_dir($upload_dir)) {
                      mkdir($upload_dir);
                  }
                  if (!is_dir($imgUrl)) {
                      mkdir($imgUrl);
                  }
                  
                  //获取传递参数;
                  $file = $_FILES['file'];
                  $ext = explode('.', $_FILES['file']['name']);
                  $ext = end($ext);
                  $fileName = md5(time()) . "." . $ext;
                  
                  //执行上传;
                  if (isset($_FILES['file']) && $_FILES['file']['error'] == "0") {
                      //上传图片;
                      move_uploaded_file($file['tmp_name'], $imgUrl . "/" . $fileName);
                      $safe_img = $imgUrl . "/" . $fileName;
                  
                      //返回JSON;
                      $res['code'] = "0";
                      $res['imgUrl'] = $safe_img;
                      $res['err'] = '上传成功!';
                      die(json_encode($res));
                  }
                   
                  上一篇:php数组通过array_push函数进行排序及选择排序 下一篇:没有了

                  相关文章

                  <tfoot id='e495u'></tfoot>

                    <bdo id='e495u'></bdo><ul id='e495u'></ul>
                2. <small id='e495u'></small><noframes id='e495u'>

                  <i id='e495u'><tr id='e495u'><dt id='e495u'><q id='e495u'><span id='e495u'><b id='e495u'><form id='e495u'><ins id='e495u'></ins><ul id='e495u'></ul><sub id='e495u'></sub></form><legend id='e495u'></legend><bdo id='e495u'><pre id='e495u'><center id='e495u'></center></pre></bdo></b><th id='e495u'></th></span></q></dt></tr></i><div id='e495u'><tfoot id='e495u'></tfoot><dl id='e495u'><fieldset id='e495u'></fieldset></dl></div>

                  1. <legend id='e495u'><style id='e495u'><dir id='e495u'><q id='e495u'></q></dir></style></legend>