title: How to save cropped image to a directory with Jcrop using PHP
body: <p>I can crop my images and click on crop. but then something goes wrong, because i don't know exactly how to save this image.</p>
  
  <p>I use imagecreatefromjpeg from php.
  this code look like this:</p>
  
  <pre><code>&lt;?php
  SESSION_start();
  if ($_SERVER['REQUEST_METHOD'] == 'POST')
  {
  $targ_w = 200;
  $targ_h = 400;
  $jpeg_quality = 90;
  
  $src = $_SESSION['target_path'];
  $img_r = imagecreatefromjpeg($src);
  $dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
  
  imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
  $targ_w,$targ_h,$_POST['w'],$_POST['h']);
  
  //header('Content-type: image/jpeg');
  imagejpeg($dst_r, 'uploads/cropped/' . 'filename');
  
  exit;
  }
  
  ?&gt;
  </code></pre>
  
  <p>My php code for saving the original image looks like this:</p>
  
  <pre><code>     &lt;?php 
           session_start();
           $target = "uploads/"; 
           $target = $target . basename( $_FILES['filename']['name']) ; 
           $_SESSION['target_path'] = $target;
  
           $ok=1; 
           if(move_uploaded_file($_FILES['filename']['tmp_name'], $target)) 
           {
           echo "De afbeelding *". basename( $_FILES['filename']['name']). "* is geupload naar de map 'uploads'";
           } 
           else {
           echo "Sorry, er is een probleem met het uploaden van de afbeelding.";
           }
      ?&gt; 
  </code></pre>
  
  <p>how do i save the cropped image?
  and is there a way to save the cropped image by overwriting the original so i get only the cropped image?</p>
  
  <p>thanks in advance.</p>
  
  <p><strong>EDIT: 
  I can save 1 photo now. i edited my code to: 
      imagejpeg($dst_r, 'uploads/cropped/' . $filename .'boek.jpg');
  But i have to make a function who can save multiple files with each another name. and maybe overwrite the original image, who is saved in 'uploads/'</strong></p>