Böyle bir şey çalışması gerekir:
function isBelowAllowedPath($file, $allowedPath)
{
return ( strpos( realpath($file), $allowedPath) === 0 );
}
isBelowAllowedPath('/etc/passwd', '/var/www/pub/'); // false
isBelowAllowedPath('/var/www/pub/index.htm', '/var/www/pub/'); // true
Emin $ dosyası yapmak istiyorsanız ya da var
function isBelowAllowedPath($file, $allowedPath)
{
return file_exists( $allowedPath . basename(realpath($file)) );
}
isBelowAllowedPath('/../../../../etc/passwd', '/var/www/pub/'); // false
isBelowAllowedPath('index.htm', '/var/www/pub/'); // true
veya (bir yolu altında) $ AllowedPaths belirli bir listede olmak $ dosyasını isterseniz
function isInAllowedPath($file, array $allowedPath)
{
$fileDir = realpath(dirname($file));
return (in_array($fileDir, $allowedPath));
}
$allowed = array('/var/www/pub/', 'somewhere/else');
isInAllowedPath('/var/www/pub/foo/index.htm', $allowed); // false
isInAllowedPath('/var/www/pub/index.htm', $allowed); // true