static public function isFileInsideDirectory($filename, $directory)
    {
        $canonicalDirectory = realpath($directory);
        if (false === $canonicalDirectory) {
            return false;
        }
        $canonicalFilename = realpath($canonicalDirectory . DIRECTORY_SEPARATOR . $filename);
        if (false === $canonicalFilename) {
            return false;
        }
        return 0 === strpos($canonicalFilename, $canonicalDirectory);
    }
static public function isFileInsideDirectory($filename, $directory)
    {
        $canonicalDirectory = realpath($directory);
        if (false === $canonicalDirectory) {
            return false;
        }
        $canonicalFilename = realpath($canonicalDirectory . DIRECTORY_SEPARATOR . $filename);
        if (false === $canonicalFilename) {
            return false;
        }
        return 0 === strpos($canonicalFilename, $canonicalDirectory);
    }
static public function isFileInsideDirectory ( $ filename , $ directory ) { $ canonicalDirectory = realpath ( $ directory ) ; if ( false === $ canonicalDirectory ) { return false ; } $ canonicalFilename = realpath ( $ canonicalDirectory . DIRECTORY_SEPARATOR . $ filename ) ; if ( false === $ canonicalFilename ) { return false ; } return 0 === strpos ( $ canonicalFilename , $ canonicalDirectory ) ; }
Helps prevent 'path traversal' attacks

@param $filename
@param $directory
@return bool
Helps prevent path traversal attacks