Check for directory traversal attack.
<?php
// access within this base path folder
$basePath = 'folder/';
// example path of restricted folder
$path = 'folder/test/../../root';
$realBasePath = realpath($basePath);
$realPath = realpath($path);
if ($realPath === false || strpos($realPath, $realBasePath) !== 0) {
echo 'Directory traversal attack!';
}