title: How to save generated image (from imagecreatefromjepeg) in the server (not in the PC)?
body: <p>i am asked to create a from that will ask for text inputs and a photo to be uploaded. then create an image wherein those are displayed. the generated image must then be saved to the server (not using database). i have a code here that successfully generates the image (i used imagejpeg and imagecreatefromjpeg in this case. but then i still need to save it to the server with the file extension .jpg.  i also need to give it a unique name.</p>
  
  <p>i tried using <strong>header('Content-Disposition: attachment; filename="image.jpg"');</strong> but what it does is save it to the PC not in the server. below is my code. please feel frre to edit it. also, please leave some comments so that i can understand it and not just do copy paste. thank you so much in advance for you help. i really need to make it working by now. thanks again</p>
  
  <pre><code>    //for textbox input
  $title = $_POST['title'];
  $story = "My super story begins with" . $_POST['story'] . " My task was " . $_POST['task'] ." With the super power of ". $_POST['power'] ." I solved it by ". $_POST['solve'] ." The result was". $_POST['result'];
  
  
  //header('Content-Disposition: attachment; filename="image.jpg"'); //this works for saving img to PC or downloading it force .jpg ext
  header('Content-Type: image/jpeg');
  
  
  $upload = $uploadFilename; //this is for getting the uploaded file
  $im = imagecreatefromjpeg("bg2.jpg");
  $img2 = imagecreatefromjpeg($upload);
  $black = imagecolorallocate($im, 0, 0, 0);
  $font = 'arialbi.ttf';
  $font2 = 'ariali.ttf';
  
  imagettftext($im, 24, 0, $width_sum, 300, $black, $font, $title);
  
  
  $newtext = wordwrap($story, 35, "\n", true);
  $newertext2 = explode  ("\n", $newtext);
  imagettftext($im, 8, 0, 300, 362, $black, $font, $story);
  imagettftext($im, 8, 0, 300, 374, $black, $font2,$story);
  imagettftext($im, 8, 0, 300, 386, $black, $font, $story);
  imagettftext($im, 8, 0, 300, 398, $black, $font2, $story);
  imagettftext($im, 8, 0, 300, 410, $black, $font, $story);
  imagettftext($im, 8, 0, 300, 422, $black, $font2, $story);
  imagettftext($im, 8, 0, 300, 434, $black, $font,$story);
  imagettftext($im, 8, 0, 300, 446, $black, $font2, $story);
  imagettftext($im, 8, 0, 300, 458, $black, $font,$story);
  imagettftext($im, 8, 0, 300, 570, $black, $font2, $story);
  imagettftext($im, 8, 0, 300, 582, $black, $font, $story);
  
  
  imagecopymerge($im, $img2, 10, 350, 0, 0, imagesx($img2), imagesy($img2), 100);
  imagejpeg($im, null, 100);
  
  
  //closing for imagejpeg
  imagejpeg($im);
  imagedestroy($im);
  </code></pre>