title: Php scandir limit access
body: <p>I make a simple file manager script for my site. </p>
  
  <p>In order to list all files and categories in a folder I use <code>scandir()</code> function. I have a variable that contains the basic path, like <code>$path = /var/www/mysite/uploads</code>. Then I have a function which takes GET variable containing additional path, like <code>/my/photos/</code> so I return the contents of <code>/var/www/mysite/uploads/my/photos</code>.</p>
  
  <p>The problem is that if a user sends <code>../../../</code>, something like that, he'll go up on the directory tree and will be able to watch the whole system.</p>
  
  <p>How can I restrict this? The only thing I've googled whas about <code>chroot</code>, but not sure if this is what I need</p>