title: Crop Image and upload with php
body: <p>I have a crop image script. How can the script upload the cropped image when the user clicks the save button? How can I make the PHP the cropped image and upload to server?</p>
  
  <p>The documentation is here on <a href="https://github.com/fengyuanchen/cropperjs" rel="nofollow noreferrer">github - cropperjs</a>.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;meta http-equiv="x-ua-compatible" content="ie=edge"&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"&gt;
    &lt;title&gt;Cropper.js&lt;/title&gt;
    &lt;!-- &lt;link rel="stylesheet" href="dist/cropper.css"&gt; --&gt;
    &lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/cropperjs/0.8.1/cropper.css" /&gt;
    
    &lt;style&gt;
      .container {
        max-width: 640px;
        margin: 20px auto;
      }
  
      img {
        max-width: 100%;
      }
    &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
    &lt;div class="container"&gt;
      &lt;h1&gt;Cropper with a range of aspect ratio&lt;/h1&gt;
   
      &lt;div&gt;
        &lt;img id="image" src="https://fengyuanchen.github.io/cropperjs/images/picture.jpg" alt="Picture"&gt;
      &lt;/div&gt;
   &lt;button onclick="cropper.getCroppedCanvas()"&gt;Save&lt;/button&gt;
    &lt;/div&gt;
  
    &lt;!-- &lt;script src="dist/cropper.js"&gt;&lt;/script&gt; --&gt;
    &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/cropperjs/0.8.1/cropper.js"&gt;&lt;/script&gt;
    &lt;script&gt;
      window.addEventListener('DOMContentLoaded', function () {
        var image = document.querySelector('#image');
        var minAspectRatio = 1.0;
        var maxAspectRatio = 1.0;
        var cropper = new Cropper(image, {
          ready: function () {
            var cropper = this.cropper;
            var containerData = cropper.getContainerData();
            var cropBoxData = cropper.getCropBoxData();
            var aspectRatio = cropBoxData.width / cropBoxData.height;
            var newCropBoxWidth;
  
            if (aspectRatio &lt; minAspectRatio || aspectRatio &gt; maxAspectRatio) {
              newCropBoxWidth = cropBoxData.height * ((minAspectRatio + maxAspectRatio) / 2);
  
              cropper.setCropBoxData({
                left: (containerData.width - newCropBoxWidth) / 2,
                width: newCropBoxWidth
              });
            }
          },
          cropmove: function () {
            var cropper = this.cropper;
            var cropBoxData = cropper.getCropBoxData();
            var aspectRatio = cropBoxData.width / cropBoxData.height;
  
            if (aspectRatio &lt; minAspectRatio) {
              cropper.setCropBoxData({
                width: cropBoxData.height * minAspectRatio
              });
            } else if (aspectRatio &gt; maxAspectRatio) {
              cropper.setCropBoxData({
                width: cropBoxData.height * maxAspectRatio
              });
            }
          }
        });
      });
    &lt;/script&gt;
    &lt;!-- FULL DOCUMENTATION ON https://github.com/fengyuanchen/cropperjs --&gt;
    &lt;!-- My question is: How do i get the cropped image and upload via php ? --&gt;
   
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>