/** * Function used to find a file by name * * This function will attempt to retrieve a valid file from the file list. * * @param string $name The name of the file (no default) */ private static function HandleFile($name) { self::SetError(404, 'ERROR_FILE_NOT_FOUND'); // Set 404 incase anything goes wrong if (preg_match(LWC::REGEX_PATH, $name) && !preg_match(LWC::REGEX_PATH_BREAKOUT, $name)) { if (is_array(self::$files)) { foreach (self::$files as $file) { $key = $name; // Take a local copy of the name so we can modify it if ($file['folder']) { // Check if this file is actually a folder $key = dirname($name); } // Get the upper folder from the key if ($file['key'] == $key) { if (session('rank') >= $file['minrank'] && session('rank') <= $file['maxrank']) { $file['path'] = $name; // Set proper path of file self::$file = $file; // Set active file } else { self::SetError(403, 'ERROR_FILE_FORBIDDEN'); } // User is not allowed to download this file } } } } }