title: convert base64 to real image and save in a folder php
body: <p>I found the below php file upload from the web and it worked fine till i designed a web application in angular 4 which a photo before being upload will have to be cropped. When the image is cropped, it saves the cropped image in a base64 format, now my problem is how i can configure my current php script to convert the base64 image to a real image</p>
  
  <pre><code>if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    echo json_encode(array('status' =&gt; false));
    exit;
  }
  
  $path = '../myapp/img_folder/';
  
  if (isset($_FILES['file'])) {
    $originalName = $_FILES['file']['name'];
    $ext = '.'.pathinfo($originalName, PATHINFO_EXTENSION);
    $generatedName = md5($_FILES['file']['tmp_name']).$ext;
    $filePath = $path.$generatedName;
  
    if (!is_writable($path)) {
      echo json_encode(array(
        'status' =&gt; false,
        'msg'    =&gt; 'Destination directory not writable.'
      ));
      exit;
    }
  
    if (move_uploaded_file($_FILES['file']['tmp_name'], $filePath)) {
      echo json_encode(array(
        'status'        =&gt; true,
        'originalName'  =&gt; $originalName,
        'generatedName' =&gt; $generatedName
      ));
    }
  }
  else {
    echo json_encode(
      array('status' =&gt; false, 'msg' =&gt; 'No file uploaded.')
    );
    exit;
  }
  </code></pre>