Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Utility class for browsing of files.

Copyright: 2008 Petr Skoda (http://skodak.org)
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 237 lines (10 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: file_browser  - X-Ref

This class provides the main entry point for other code wishing to get information about files.

The whole file storage for a Moodle site can be seen as a huge virtual tree.
The spine of the tree is the tree of contexts (system, course-categories,
courses, modules, also users). Then, within each context, there may be any number of
file areas, and a file area contains folders and files. The various file_info
subclasses return info about the things in this tree. They should be obtained
from an instance of this class.

This virtual tree is different for each user depending of his/her current permissions.
Some branches such as draft areas are hidden, but accessible.

Always use this abstraction when you need to access module files from core code.

get_file_info($context = NULL, $component = NULL, $filearea = NULL, $itemid = NULL, $filepath = NULL, $filename = NULL)   X-Ref
Looks up file_info instance

param: stdClass $context context object
param: string $component component
param: string $filearea file area
param: int $itemid item ID
param: string $filepath file path
param: string $filename file name
return: file_info|null file_info instance or null if not found or access not allowed

get_file_info_context_system($context, $component, $filearea, $itemid, $filepath, $filename)   X-Ref
Returns info about the files at System context

param: object $context context object
param: string $component component
param: string $filearea file area
param: int $itemid item ID
param: string $filepath file path
param: string $filename file name
return: file_info instance or null if not found or access not allowed

get_file_info_context_user($context, $component, $filearea, $itemid, $filepath, $filename)   X-Ref
Returns info about the files at User context

param: stdClass $context context object
param: string $component component
param: string $filearea file area
param: int $itemid item ID
param: string $filepath file path
param: string $filename file name
return: file_info|null file_info instance or null if not found or access not allowed

get_file_info_context_coursecat($context, $component, $filearea, $itemid, $filepath, $filename)   X-Ref
Returns info about the files at Course category context

param: stdClass $context context object
param: string $component component
param: string $filearea file area
param: int $itemid item ID
param: string $filepath file path
param: string $filename file name
return: file_info|null file_info instance or null if not found or access not allowed

get_file_info_context_course($context, $component, $filearea, $itemid, $filepath, $filename)   X-Ref
Returns info about the files at Course category context

param: stdClass $context context object
param: string $component component
param: string $filearea file area
param: int $itemid item ID
param: string $filepath file path
param: string $filename file name
return: file_info|null file_info instance or null if not found or access not allowed

get_file_info_context_module($context, $component, $filearea, $itemid, $filepath, $filename)   X-Ref
Returns info about the files at Course category context

param: context $context context object
param: string $component component
param: string $filearea file area
param: int $itemid item ID
param: string $filepath file path
param: string $filename file name
return: file_info|null file_info instance or null if not found or access not allowed

is_enrolled($courseid)   X-Ref
Check if user is enrolled into the course

This function keeps a cache of enrolled courses because it may be called multiple times for many courses in one request

param: int $courseid
return: bool