file_support
class file_support
| internal |
File storage utility wrapper for Moodle's File Storage API.
This class centralizes file operations using Moodle's file_storage system, providing a consistent interface for file management across the plugin.
All file operations should go through this class to ensure proper handling of Moodle's file storage architecture and to maintain consistency.
Constants
| COMPONENT |
|
Methods
Retrieves the Moodle file storage instance.
Retrieves a single file from a file area.
Retrieves all files from a file area (excluding directories).
Retrieves a specific file by its path components.
Retrieves a file by its database ID.
Creates a file record from an existing stored file (copy).
Creates a file from raw string content.
Creates a file from a local filesystem path.
Deletes a specific file.
Deletes a file by its ID.
Deletes all files in a specific file area (optionally limited by itemid).
Retrieves the URL for a stored file.
Checks if a file area contains any files.
Calculates the total size of files in a file area.
Counts the number of files in a file area.
Validates if a file is a valid image.
Retrieves file content as a string.
Retrieves file content as a resource handle.
Details
at line 48
static file_storage
get_storage()
Retrieves the Moodle file storage instance.
at line 66
static false|stored_file|null
get_file(int $contextid, string $component, string $filearea, int $itemid, bool $validimage = false)
Retrieves a single file from a file area.
Useful for areas that should contain only one file (e.g., profile pictures, logos).
at line 105
static array
get_area_files(int $contextid, string $component, string $filearea, int $itemid)
Retrieves all files from a file area (excluding directories).
at line 142
static stored_file|null
get_file_by_path(int $contextid, string $component, string $filearea, int $itemid, string $filepath, string $filename)
Retrieves a specific file by its path components.
at line 169
static stored_file|null
get_file_by_id(int $fileid)
Retrieves a file by its database ID.
at line 198
static stored_file|null
create_file_from_stored(stored_file $sourcefile, int $contextid, string $component, string $filearea, int $itemid, string $filepath = '/', string|null $filename = null)
Creates a file record from an existing stored file (copy).
Useful for duplicating files or moving them between areas.
at line 242
static stored_file|null
create_file_from_string(int $contextid, string $component, string $filearea, int $itemid, string $filepath, string $filename, string $content)
Creates a file from raw string content.
at line 283
static stored_file|null
create_file_from_pathname(int $contextid, string $component, string $filearea, int $itemid, string $filepath, string $filename, string $pathname)
Creates a file from a local filesystem path.
at line 318
static bool
delete_file(stored_file $file)
Deletes a specific file.
at line 336
static bool
delete_file_by_id(int $fileid)
Deletes a file by its ID.
at line 363
static bool
delete_area_files(int $contextid, string $component, string $filearea, false|int $itemid = false)
Deletes all files in a specific file area (optionally limited by itemid).
at line 387
static string
get_file_url(stored_file $file, bool $forcedownload = false, string|null $preview = null)
Retrieves the URL for a stored file.
at line 438
static bool
has_files(int $contextid, string $component, string $filearea, int $itemid)
Checks if a file area contains any files.
at line 472
static int
get_area_size(int $contextid, string $component, string $filearea, int $itemid)
Calculates the total size of files in a file area.
at line 504
static int
count_area_files(int $contextid, string $component, string $filearea, int $itemid)
Counts the number of files in a file area.
at line 520
static bool
is_valid_image(stored_file $file)
Validates if a file is a valid image.
at line 538
static string|null
get_content(stored_file $file)
Retrieves file content as a string.
at line 556
static null|resource
get_content_file_handle(stored_file $file)
Retrieves file content as a resource handle.