See Release Notes
Long Term Support Release
Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]
Core file system class definition.
Copyright: | 2017 Andrew Nicols <andrew@nicols.co.uk> |
License: | http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
File Size: | 674 lines (26 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 0 files |
file_system:: (26 methods):
readfile()
get_local_path_from_storedfile()
get_remote_path_from_storedfile()
is_file_readable_locally_by_storedfile()
is_file_readable_remotely_by_storedfile()
is_file_readable_locally_by_hash()
is_file_readable_remotely_by_hash()
is_file_removable()
get_content()
list_files()
extract_to_pathname()
extract_to_storage()
add_storedfile_to_archive()
add_to_curl_request()
get_imageinfo()
is_image_from_storedfile()
get_imageinfo_from_path()
xsendfile_file()
xsendfile()
supports_xsendfile()
validate_hash_and_file_size()
get_content_file_handle()
get_file_handle_for_path()
mimetype_from_hash()
mimetype_from_storedfile()
cron()
Class: file_system - X-Ref
File system class used for low level access to real files in filedir.readfile(stored_file $file) X-Ref |
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. param: stored_file $file The file to serve. return: void |
get_local_path_from_storedfile(stored_file $file, $fetchifnotfound = false) X-Ref |
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. param: stored_file $file The file to serve. param: bool $fetchifnotfound Whether to attempt to fetch from the remote path if not found. return: string full path to pool file with file content |
get_remote_path_from_storedfile(stored_file $file) X-Ref |
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. param: stored_file $file The file to serve. return: string full path to pool file with file content |
is_file_readable_locally_by_storedfile(stored_file $file, $fetchifnotfound = false) X-Ref |
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. param: stored_file $file The file to ensure is available. param: bool $fetchifnotfound Whether to attempt to fetch from the remote path if not found. return: bool |
is_file_readable_remotely_by_storedfile(stored_file $file) X-Ref |
Determine whether the file is present on the local file system somewhere. param: stored_file $file The file to ensure is available. return: bool |
is_file_readable_locally_by_hash($contenthash, $fetchifnotfound = false) X-Ref |
Determine whether the file is present on the file system somewhere given the contenthash. param: string $contenthash The contenthash of the file to check. param: bool $fetchifnotfound Whether to attempt to fetch from the remote path if not found. return: bool |
is_file_readable_remotely_by_hash($contenthash) X-Ref |
Determine whether the file is present locally on the file system somewhere given the contenthash. param: string $contenthash The contenthash of the file to check. return: bool |
is_file_removable($contenthash) X-Ref |
Check whether a file is removable. This must be called prior to file removal. param: string $contenthash return: bool |
get_content(stored_file $file) X-Ref |
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. param: stored_file $file The file to retrieve return: string The full file content |
list_files($file, file_packer $packer) X-Ref |
List contents of archive. param: stored_file $file The archive to inspect param: file_packer $packer file packer instance return: array of file infos |
extract_to_pathname(stored_file $file, file_packer $packer, $pathname, file_progress $progress = null) X-Ref |
Extract file to given file path (real OS filesystem), existing files are overwritten. param: stored_file $file The archive to inspect param: file_packer $packer File packer instance param: string $pathname Target directory param: file_progress $progress progress indicator callback or null if not required return: array|bool List of processed files; false if error |
extract_to_storage(stored_file $file, file_packer $packer, $contextid,$component, $filearea, $itemid, $pathbase, $userid = null, file_progress $progress = null) X-Ref |
Extract file to given file path (real OS filesystem), existing files are overwritten. param: stored_file $file The archive to inspect param: file_packer $packer file packer instance param: int $contextid context ID param: string $component component param: string $filearea file area param: int $itemid item ID param: string $pathbase path base param: int $userid user ID param: file_progress $progress Progress indicator callback or null if not required return: array|bool list of processed files; false if error |
add_storedfile_to_archive(stored_file $file, file_archive $filearch, $archivepath) X-Ref |
Add file/directory into archive. param: stored_file $file The file to archive param: file_archive $filearch file archive instance param: string $archivepath pathname in archive return: bool success |
add_to_curl_request(stored_file $file, &$curlrequest, $key) X-Ref |
Adds this file path to a curl request (POST only). param: stored_file $file The file to add to the curl request param: curl $curlrequest The curl request object param: string $key What key to use in the POST request return: void |
get_imageinfo(stored_file $file) X-Ref |
Returns information about image. Information is determined from the file content param: stored_file $file The file to inspect return: mixed array with width, height and mimetype; false if not an image |
is_image_from_storedfile(stored_file $file) X-Ref |
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. param: stored_file $file The file to check return: bool |
get_imageinfo_from_path($path) X-Ref |
Returns image information relating to the specified path or URL. param: string $path The full path of the image file. return: array|bool array that containing width, height, and mimetype or false if cannot get the image info. |
xsendfile_file(stored_file $file) X-Ref |
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. param: stored_file $file The file to send return: bool success |
xsendfile($contenthash) X-Ref |
Serve file content using X-Sendfile header. Please make sure that all headers are already sent and the all access control checks passed. param: string $contenthash The content hash of the file to be served return: bool success |
supports_xsendfile() X-Ref |
Returns true if filesystem is configured to support xsendfile. return: bool |
validate_hash_and_file_size($contenthash, $pathname) X-Ref |
Validate that the content hash matches the content hash of the file on disk. param: string $contenthash The current content hash to validate param: string $pathname The path to the file on disk return: array The content hash (it might change) and file size |
get_content_file_handle(stored_file $file, $type = stored_file::FILE_HANDLE_FOPEN) X-Ref |
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. param: stored_file $file The file to retrieve a handle for param: int $type Type of file handle (FILE_HANDLE_xx constant) return: resource file handle |
get_file_handle_for_path($path, $type = stored_file::FILE_HANDLE_FOPEN) X-Ref |
Return a file handle for the specified path. This abstraction should be used when overriding get_content_file_handle in a new file system. param: string $path The path to the file. This shoudl be any type of path that fopen and gzopen accept. param: int $type Type of file handle (FILE_HANDLE_xx constant) return: resource |
mimetype_from_hash($contenthash, $filename) X-Ref |
Retrieve the mime information for the specified stored file. param: string $contenthash param: string $filename return: string The MIME type. |
mimetype_from_storedfile($file) X-Ref |
Retrieve the mime information for the specified stored file. param: stored_file $file The stored file to retrieve mime information for return: string The MIME type. |
cron() X-Ref |
Run any periodic tasks which must be performed. |