title: Covert ../ Into Real Directories PHP
body: <p>I am making a small file browsing script using PHP and Javascript and I have come into a small issue. The current directory is stored as GET in the url as <code>index.php?dir=/projects/jphp</code> when it is in the base. I then store this in the variabe <code>$scandir</code> using:</p>
  
  <pre><code>$scandir = $_GET['dir'];
  </code></pre>
  
  <p>as the fiels are listed in a table so users can look thorugh them, folders are hyperlinked like this:</p>
  
  <pre><code>&lt;td&gt;&lt;a style="color: red;" href="edit.php?pid=&lt;?php echo $project['id'] ?&gt;&amp;dir=&lt;?php echo $scandir . "/" . $thisfile; ?&gt;"&gt;&lt;?php echo $thisfile; ?&gt;&lt;/a&gt;&lt;/td&gt;
  </code></pre>
  
  <p>The variable <code>$thisfile</code> is populated using a <code>foreach()</code> loop that goes through every file in the directory.
  <br />
  As The user starts to browse the folders and files, the file address gets messy so, for example, after a minute of browsing the files, the <code>$_GET['dir'];</code> looks like </p>
  
  <pre><code>projects/jphp/js/../js/../../../projects/jphp
  </code></pre>
  
  <p>is there any way to keep the paths simple as the path above is the exact same as</p>
  
  <pre><code>projects/jphp
  </code></pre>
  
  <p>If you know how to covert the top into the bottom, that would be great, thanks! I might not have explained this well so let me know you I am not making sense.</p>