【问题标题】:I need upload image into a folder using php我需要使用 php 将图像上传到文件夹中
【发布时间】:2017-06-06 21:36:53
【问题描述】:

我需要使用 php 将图像上传到文件夹中

我使用 Cropit 插件 链接:http://scottcheng.github.io/cropit/

这是我的代码:

查询:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script src="pro_pic_crop_mobile/jquery.cropit.js"></script>

CSS:

<style>
  .cropit-preview {
    background-color: #f8f8f8;
    background-size: cover;
    border: 1px solid #ccc;
    border-radius: 3px;
    margin-top: 7px;
   width: 436px;
      height: 580px;
  }

  .cropit-preview-image-container {
    cursor: move;
  }

  .image-size-label {
    margin-top: 10px;
  }

  input {
    display: block;
  }

  button[type="submit"] {
    margin-top: 10px;
  }

  #result {
    margin-top: 10px;
    width: 900px;
  }

  #result-data {
    display: block;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    word-wrap: break-word;
  }
</style>

HTML 和 JQUERY:

<div align="center">

<form id="img" name="img" method="post" action="#" enctype="multipart/form-data">
  <div class="image-editor">
    <input type="file" class="cropit-image-input">
    <div class="cropit-preview"></div>
    <div class="image-size-label">
      Resize image
    </div>
    <input type="range" class="cropit-image-zoom-input">
    <input type="hidden" name="image-data" class="hidden-image-data" />

    <input name="submit" type="submit" value="Submit" />
  </div>
</form>

<div id="result">
  <code>$form.serialize() =</code>
  <code id="result-data"></code>

</div>


</div>


<script>
  $(function() {
    $('.image-editor').cropit();

    $('form').submit(function() {
      // Move cropped image data to hidden input
      var imageData = $('.image-editor').cropit('export');
      $('.hidden-image-data').val(imageData);

      // Print HTTP request params
      var formValue = $(this).serialize();
      $('#result-data').text(formValue);

      // Prevent the form from actually submitting
      return false;
    });
  });
</script>

首先我提交图像,然后使用 jquery 将 base64 值放入 div id,然后我想使用 php 将调整大小的图像上传到文件夹中。

提前谢谢大家:)

【问题讨论】:

    标签: php jquery image resize crop


    【解决方案1】:

    一种方法是使用Document Object Model

    <?php
    $randomDiv =
                "<div id='myId' class='myClass'>
                     //inner elements
                 </div>";
    
    $documentObj = new DOMDocument();
    $documentObj->loadHtml($randomDiv);
    $elementObj = $documentObj->getElementsByClassName('myClass');
    echo($elementObj[0]->getAttribute('id'));
    ?>
    

    【讨论】:

      猜你喜欢
      • 2021-09-29
      • 1970-01-01
      • 1970-01-01
      • 2018-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      相关资源
      最近更新 更多