title: Add watermark to file during upload
body: <p>I'm trying to make an upload function which adds a watermark to every file uploaded in memory and then saves the files to a specific folder. However, I can't get the watermark part of the code to work. I know for sure that the upload functions works without the watermark code added to it. I believe that the error must be where the watermark code "transfers" the temporary file to the code that moves the file to the hard drive. How can I fix this problem?</p>
  
  <p>The code is as follows:</p>
  
  <pre><code>foreach($_FILES['files']['tmp_name'] as $key =&gt; $tmp_name ){
  
              $file_name = $_FILES['files']['name'][$key];
              $file_size =$_FILES['files']['size'][$key];
              $file_tmp =$_FILES['files']['tmp_name'][$key];
              //$file_type=$_FILES['files']['type'][$key];    
  
              //if($file_size &gt; 2097152){
  
                  //$errors[]='File size must be less than 2 MB';
              //}
              // echo '&lt;img src="../images/watermark.gif"&gt;';
  
              $q = "INSERT INTO media (file_name, album_id, file_size) VALUES ('$file_name','$album_id', '$file_size')";
  
              $r = mysqli_query ($dbc, $q);
  
              $desired_dir = '../../customers/' . $customerFolder . '/';
  
              // load the watermark and the photo
              $watermark = imagecreatefromgif('../images/watermark.gif');
              $photo = imagecreatefromjpeg($file_tmp);
  
              // center watermark on the photo
              $wx = imagesx($photo)/2 - imagesx($watermark)/2;
              $wy = imagesy($photo)/2 - imagesy($watermark)/2;
  
              imagecopy($photo, $watermark, $wx, $wy, 0, 0, imagesx($watermark), imagesy($watermark));
  
              if(empty($errors)==true){
  
                      move_uploaded_file($photo,"$desired_dir".$file_name);
  
                  //mysql_query($q);  
  
              }else{
                  print_r($errors);
              }
          }
  </code></pre>