title: rename file names php
body: <p>I need to swap file names using php. For example I have two files, first file: image1.jpg and the second file: image2.jpg. I want to swap the file names. So that the first file will be names image2.jpg and the second file will be named image1.jpg;</p>
  
  <p>my failed attempt at this:</p>
  
  <pre><code>function swap($name1, $name2)
  {
      $tempName1 = "temporary1";
      $tempName2 = "temporary2";
      myRename($name1, $tempName1);
      myRename($name2, $tempName2);
      myRename($tempName1, $name2);
      myRename($tempName2, $name1);
  }
  
  function myRename($oldTitle, $newTitle)
  {
      $oldDirectory = "images/".$oldTitle.".jpg";
      $newDirectory = "images/".$newTitle.".jpg";
      rename($oldDirectory, $newDirectory);
  }
  </code></pre>
  
  <p>How can I successfully swap the names?</p>