title: How can I move a file to another folder using php?
body: <p>I have an upload form where users can upload images that are currently being uploaded to a folder I made called 'temp' and their locations are saved in an array called $_SESSION['uploaded_photos']. Once the user pushes the 'Next Page' button, I want it to move the files to a new folder that is dynamically created right before that.</p>
  
  <pre><code>if(isset($_POST['next_page'])) { 
    if (!is_dir('../images/uploads/listers/'.$_SESSION['loggedin_lister_id'])) {
      mkdir('../images/uploads/listers/'.$_SESSION['loggedin_lister_id']);
    }
  
    foreach($_SESSION['uploaded_photos'] as $key =&gt; $value) { 
      $target_path = '../images/uploads/listers/'.$_SESSION['loggedin_lister_id'].'/';
      $target_path = $target_path . basename($value); 
  
      if(move_uploaded_file($value, $target_path)) {
        echo "The file ".  basename($value). " has been uploaded&lt;br /&gt;";
      } else{
        echo "There was an error uploading the file, please try again!";
      }
  
    } //end foreach
  
  } //end if isset next_page
  </code></pre>
  
  <p>An example for a $value that is being used is:</p>
  
  <blockquote>
    <p>../images/uploads/temp/IMG_0002.jpg</p>
  </blockquote>
  
  <p>And an example of a $target_path that is being used is:</p>
  
  <blockquote>
    <p>../images/uploads/listers/186/IMG_0002.jpg</p>
  </blockquote>
  
  <p>I can see the file sitting in the temp folder, both of those paths look good to me and I checked to make sure that the mkdir function actually created the folder which it did well.</p>
  
  <p>How can I move a file to another folder using php?</p>