title: Move a file and rename it
body: <p>Figured PHP's rename would be my best bet. I didn't see many examples on how to use relative URLs in it though, so I kind of compromised. Either way, this give me permission denied:</p>
  
  <p>I want to do this:</p>
  
  <pre><code>$file = "../data.csv";
  rename("$file", "../history/newname.csv");
  </code></pre>
  
  <p>Where <strong>../</strong> of course would go back 1 directory from where the script is being ran. I couldn't figure out a way...so I did this instead:</p>
  
  <pre><code>$file = "data.csv";
  $path = dirname(realpath("../".$file));
  rename("$path/$file", "$path/history/newname.csv");
  </code></pre>
  
  <p>However I am getting <strong>permission denied</strong> (yes the history folder is owned by www-data, and yes data.csv is owned by www-data). I thought it was weird so I tried a simple test:</p>
  
  <pre><code>rename( 'tempfile.txt', 'tempfile2.txt' );
  </code></pre>
  
  <p>and I made sure www-data had full control over tempfile.txt...still got permission denied. Why? does the file your renaming it to have to exist? can you not rename like linux's mv? So I instead just copy() and unlink()?</p>