Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
|
Public Member Functions | |
add_file_from_path ($pathname, $contenthash=null) | |
Add the supplied file to the file system. | |
add_file_from_string ($content) | |
Add a file with the supplied content to the file system. | |
add_storedfile_to_archive (stored_file $file, file_archive $filearch, $archivepath) | |
Add file/directory into archive. | |
add_to_curl_request (stored_file $file, &$curlrequest, $key) | |
Adds this file path to a curl request (POST only). | |
copy_content_from_storedfile (stored_file $file, $target) | |
Copy content of file to given pathname. | |
cron () | |
Run any periodic tasks which must be performed. | |
extract_to_pathname (stored_file $file, file_packer $packer, $pathname, file_progress $progress=null) | |
Extract file to given file path (real OS filesystem), existing files are overwritten. | |
extract_to_storage (stored_file $file, file_packer $packer, $contextid, $component, $filearea, $itemid, $pathbase, $userid=null, file_progress $progress=null) | |
Extract file to given file path (real OS filesystem), existing files are overwritten. | |
get_content (stored_file $file) | |
Get the content of the specified stored file. | |
get_content_file_handle (stored_file $file, $type=stored_file::FILE_HANDLE_FOPEN) | |
Returns file handle - read only mode, no writing allowed into pool files! | |
get_imageinfo (stored_file $file) | |
Returns information about image. | |
get_local_path_from_storedfile (stored_file $file, $fetchifnotfound=false) | |
Get the full path on disk for the specified stored file. | |
get_psr_stream (stored_file $file) | |
Get a PSR7 Stream for the specified file which implements the PSR Message StreamInterface. | |
get_remote_path_from_storedfile (stored_file $file) | |
Get a remote filepath for the specified stored file. | |
is_file_readable_locally_by_hash ($contenthash, $fetchifnotfound=false) | |
Determine whether the file is present on the file system somewhere given the contenthash. | |
is_file_readable_locally_by_storedfile (stored_file $file, $fetchifnotfound=false) | |
Determine whether the file is present on the file system somewhere. | |
is_file_readable_remotely_by_hash ($contenthash) | |
Determine whether the file is present locally on the file system somewhere given the contenthash. | |
is_file_readable_remotely_by_storedfile (stored_file $file) | |
Determine whether the file is present on the local file system somewhere. | |
is_image_from_storedfile (stored_file $file) | |
Attempt to determine whether the specified file is likely to be an image. | |
list_files ($file, file_packer $packer) | |
List contents of archive. | |
mimetype_from_hash ($contenthash, $filename) | |
Retrieve the mime information for the specified stored file. | |
mimetype_from_storedfile ($file) | |
Retrieve the mime information for the specified stored file. | |
readfile (stored_file $file) | |
Output the content of the specified stored file. | |
remove_file ($contenthash) | |
Remove the file with the specified contenthash. | |
supports_xsendfile () | |
Returns true if filesystem is configured to support xsendfile. | |
xsendfile ($contenthash) | |
Serve file content using X-Sendfile header. | |
xsendfile_file (stored_file $file) | |
Serve file content using X-Sendfile header. | |
Protected Member Functions | |
get_imageinfo_from_path ($path) | |
Returns image information relating to the specified path or URL. | |
get_local_path_from_hash ($contenthash, $fetchifnotfound=false) | |
Get the full path for the specified hash, including the path to the filedir. | |
get_remote_path_from_hash ($contenthash) | |
Get the full path for the specified hash, including the path to the filedir. | |
validate_hash_and_file_size ($contenthash, $pathname) | |
Validate that the content hash matches the content hash of the file on disk. | |
Static Protected Member Functions | |
static | get_file_handle_for_path ($path, $type=stored_file::FILE_HANDLE_FOPEN) |
Return a file handle for the specified path. | |
static | is_file_removable ($contenthash) |
Check whether a file is removable. | |
|
abstract |
Add the supplied file to the file system.
Note: If overriding this function, it is advisable to store the file in the path returned by get_local_path_from_hash as there may be subsequent uses of the file in the same request.
string | $pathname | Path to file currently on disk |
string | $contenthash | SHA1 hash of content if known (performance only) |
array | (contenthash, filesize, newfile) |
Reimplemented in file_system_filedir.
|
abstract |
Add a file with the supplied content to the file system.
Note: If overriding this function, it is advisable to store the file in the path returned by get_local_path_from_hash as there may be subsequent uses of the file in the same request.
string | $content | file content - binary string |
array | (contenthash, filesize, newfile) |
Reimplemented in file_system_filedir.
file_system::add_storedfile_to_archive | ( | stored_file | $file, |
file_archive | $filearch, | ||
$archivepath ) |
Add file/directory into archive.
stored_file | $file | The file to archive |
file_archive | $filearch | file archive instance |
string | $archivepath | pathname in archive |
bool | success |
file_system::add_to_curl_request | ( | stored_file | $file, |
& | $curlrequest, | ||
$key ) |
Adds this file path to a curl request (POST only).
stored_file | $file | The file to add to the curl request |
curl | $curlrequest | The curl request object |
string | $key | What key to use in the POST request |
void | This needs the fullpath for the storedfile :/ Can this be achieved in some other fashion? |
|
abstract |
Copy content of file to given pathname.
stored_file | $file | The file to be copied |
string | $target | real path to the new file |
bool | success |
Reimplemented in file_system_filedir.
file_system::cron | ( | ) |
Run any periodic tasks which must be performed.
Reimplemented in file_system_filedir.
file_system::extract_to_pathname | ( | stored_file | $file, |
file_packer | $packer, | ||
$pathname, | |||
file_progress | $progress = null ) |
Extract file to given file path (real OS filesystem), existing files are overwritten.
stored_file | $file | The archive to inspect |
file_packer | $packer | File packer instance |
string | $pathname | Target directory |
file_progress | $progress | progress indicator callback or null if not required |
array|bool | List of processed files; false if error |
file_system::extract_to_storage | ( | stored_file | $file, |
file_packer | $packer, | ||
$contextid, | |||
$component, | |||
$filearea, | |||
$itemid, | |||
$pathbase, | |||
$userid = null, | |||
file_progress | $progress = null ) |
Extract file to given file path (real OS filesystem), existing files are overwritten.
stored_file | $file | The archive to inspect |
file_packer | $packer | file packer instance |
int | $contextid | context ID |
string | $component | component |
string | $filearea | file area |
int | $itemid | item ID |
string | $pathbase | path base |
int | $userid | user ID |
file_progress | $progress | Progress indicator callback or null if not required |
array|bool | list of processed files; false if error |
file_system::get_content | ( | stored_file | $file | ) |
Get the content of the specified stored file.
Generally you will probably want to use readfile() to serve content, and where possible you should see if you can use get_content_file_handle and work with the file stream instead.
stored_file | $file | The file to retrieve |
string | The full file content |
file_system::get_content_file_handle | ( | stored_file | $file, |
$type = stored_file::FILE_HANDLE_FOPEN ) |
Returns file handle - read only mode, no writing allowed into pool files!
When you want to modify a file, create a new file and delete the old one.
stored_file | $file | The file to retrieve a handle for |
int | $type | Type of file handle (FILE_HANDLE_xx constant) |
resource | file handle |
|
staticprotected |
Return a file handle for the specified path.
This abstraction should be used when overriding get_content_file_handle in a new file system.
string | $path | The path to the file. This shoudl be any type of path that fopen and gzopen accept. |
int | $type | Type of file handle (FILE_HANDLE_xx constant) |
resource |
coding_exception | When an unexpected type of file handle is requested |
file_system::get_imageinfo | ( | stored_file | $file | ) |
Returns information about image.
Information is determined from the file content
stored_file | $file | The file to inspect |
mixed | array with width, height and mimetype; false if not an image |
|
protected |
Returns image information relating to the specified path or URL.
string | $path | The full path of the image file. |
array|bool | array that containing width, height, and mimetype or false if cannot get the image info. |
|
abstractprotected |
Get the full path for the specified hash, including the path to the filedir.
Note: This must return a consistent path for the file's contenthash and the path will be in a standard local format. Streamable paths will not work. A local copy of the file will be fetched if $fetchifnotfound is tree.
The $fetchifnotfound allows you to determine the expected path of the file.
string | $contenthash | The content hash |
bool | $fetchifnotfound | Whether to attempt to fetch from the remote path if not found. |
string | The full path to the content file |
Reimplemented in file_system_filedir.
file_system::get_local_path_from_storedfile | ( | stored_file | $file, |
$fetchifnotfound = false ) |
Get the full path on disk for the specified stored file.
Note: This must return a consistent path for the file's contenthash and the path will be in a standard local format. Streamable paths will not work. A local copy of the file will be fetched if $fetchifnotfound is tree.
The $fetchifnotfound allows you to determine the expected path of the file.
stored_file | $file | The file to serve. |
bool | $fetchifnotfound | Whether to attempt to fetch from the remote path if not found. |
string | full path to pool file with file content |
Reimplemented in file_system_filedir.
file_system::get_psr_stream | ( | stored_file | $file | ) |
Get a PSR7 Stream for the specified file which implements the PSR Message StreamInterface.
stored_file | $file |
StreamInterface |
|
abstractprotected |
Get the full path for the specified hash, including the path to the filedir.
This is typically either the same as the local filepath, or it is a streamable resource.
See https://secure.php.net/manual/en/wrappers.php for further information on valid wrappers.
string | $contenthash | The content hash |
string | The full path to the content file |
Reimplemented in file_system_filedir.
file_system::get_remote_path_from_storedfile | ( | stored_file | $file | ) |
Get a remote filepath for the specified stored file.
This is typically either the same as the local filepath, or it is a streamable resource.
See https://secure.php.net/manual/en/wrappers.php for further information on valid wrappers.
stored_file | $file | The file to serve. |
string | full path to pool file with file content |
Reimplemented in file_system_filedir.
file_system::is_file_readable_locally_by_hash | ( | $contenthash, | |
$fetchifnotfound = false ) |
Determine whether the file is present on the file system somewhere given the contenthash.
string | $contenthash | The contenthash of the file to check. |
bool | $fetchifnotfound | Whether to attempt to fetch from the remote path if not found. |
bool |
file_system::is_file_readable_locally_by_storedfile | ( | stored_file | $file, |
$fetchifnotfound = false ) |
Determine whether the file is present on the file system somewhere.
A local copy of the file will be fetched if $fetchifnotfound is tree.
The $fetchifnotfound allows you to determine the expected path of the file.
stored_file | $file | The file to ensure is available. |
bool | $fetchifnotfound | Whether to attempt to fetch from the remote path if not found. |
bool |
file_system::is_file_readable_remotely_by_hash | ( | $contenthash | ) |
Determine whether the file is present locally on the file system somewhere given the contenthash.
string | $contenthash | The contenthash of the file to check. |
bool |
file_system::is_file_readable_remotely_by_storedfile | ( | stored_file | $file | ) |
Determine whether the file is present on the local file system somewhere.
stored_file | $file | The file to ensure is available. |
bool |
|
staticprotected |
Check whether a file is removable.
This must be called prior to file removal.
string | $contenthash |
bool |
file_system::is_image_from_storedfile | ( | stored_file | $file | ) |
Attempt to determine whether the specified file is likely to be an image.
Since this relies upon the mimetype stored in the files table, there may be times when this information is not 100% accurate.
stored_file | $file | The file to check |
bool |
file_system::list_files | ( | $file, | |
file_packer | $packer ) |
List contents of archive.
stored_file | $file | The archive to inspect |
file_packer | $packer | file packer instance |
array | of file infos |
file_system::mimetype_from_hash | ( | $contenthash, | |
$filename ) |
Retrieve the mime information for the specified stored file.
string | $contenthash | |
string | $filename |
string | The MIME type. |
file_system::mimetype_from_storedfile | ( | $file | ) |
Retrieve the mime information for the specified stored file.
stored_file | $file | The stored file to retrieve mime information for |
string | The MIME type. |
file_system::readfile | ( | stored_file | $file | ) |
Output the content of the specified stored file.
Note, this is different to get_content() as it uses the built-in php readfile function which is more efficient.
stored_file | $file | The file to serve. |
void |
|
abstract |
Remove the file with the specified contenthash.
Note, if overriding this function, you must check that the file is no longer in use - see {check_file_usage}.
DO NOT call directly - reserved for core!!
string | $contenthash |
Reimplemented in file_system_filedir.
file_system::supports_xsendfile | ( | ) |
Returns true if filesystem is configured to support xsendfile.
bool |
|
protected |
Validate that the content hash matches the content hash of the file on disk.
string | $contenthash | The current content hash to validate |
string | $pathname | The path to the file on disk |
array | The content hash (it might change) and file size |
file_system::xsendfile | ( | $contenthash | ) |
Serve file content using X-Sendfile header.
Please make sure that all headers are already sent and the all access control checks passed.
string | $contenthash | The content hash of the file to be served |
bool | success |
file_system::xsendfile_file | ( | stored_file | $file | ) |
Serve file content using X-Sendfile header.
Please make sure that all headers are already sent and the all access control checks passed.
This alternate method to xsendfile() allows an alternate file system to use the full file metadata and avoid extra lookups.
stored_file | $file | The file to send |
bool | success |