Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
|
Class representing local files stored in a sha1 file pool. More...
Public Member Functions | |
__construct (file_storage $fs, stdClass $file_record, $deprecated=null) | |
Constructor, this constructor should be called ONLY from the file_storage class! | |
__sleep () | |
Magic method, called during serialization. | |
__wakeup () | |
Magic method, called during unserialization. | |
add_to_curl_request (&$curlrequest, $key) | |
adds this file path to a curl request (POST only) | |
archive_file (file_archive $filearch, $archivepath) | |
Add file/directory into archive. | |
compare_to_path ($path) | |
Check whether the supplied file is the same as this file. | |
compare_to_string ($content) | |
Check whether the supplied content is the same as this file. | |
copy_content_to ($pathname) | |
Copy content of file to given pathname. | |
copy_content_to_temp ($dir='files', $fileprefix='tempup_') | |
Copy content of file to temporary folder and returns file path. | |
delete () | |
Delete file from files table. | |
delete_reference () | |
Unlink the stored file from the referenced file. | |
extract_to_pathname (file_packer $packer, $pathname, file_progress $progress=null) | |
Extract file to given file path (real OS filesystem), existing files are overwritten. | |
extract_to_storage (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. | |
generate_image_thumbnail ($width, $height) | |
Generates a thumbnail for this stored_file. | |
get_author () | |
Returns the author name of the file. | |
get_component () | |
Returns component name - this is the owner of the areas, nothing else is allowed to read or modify the files directly!! | |
get_content () | |
Returns file content as string. | |
get_content_file_handle ($type=self::FILE_HANDLE_FOPEN) | |
Returns file handle - read only mode, no writing allowed into pool files! | |
get_contenthash () | |
Returns sha1 hash of file content. | |
get_contextid () | |
Returns context id of the file. | |
get_filearea () | |
Returns file area name, this divides files of one component into groups with different access control. | |
get_filename () | |
Returns file name or '. | |
get_filepath () | |
Returns file path - starts and ends with /, are not allowed. | |
get_filesize () | |
Returns the size of file in bytes. | |
get_id () | |
Returns file id. | |
get_imageinfo () | |
Returns information about image, information is determined from the file content. | |
get_itemid () | |
Returns returns item id of file. | |
get_license () | |
Returns the license type of the file, it is a short name referred from license table. | |
get_mimetype () | |
Returns mime type of file. | |
get_parent_directory () | |
Returns parent directory, creates missing parents if needed. | |
get_pathnamehash () | |
Returns sha1 hash of all file path components sha1("contextid/component/filearea/itemid/dir/dir/filename.ext"). | |
get_psr_stream () | |
Get a read-only PSR-7 stream for this file. | |
get_reference () | |
Returns file reference. | |
get_reference_details () | |
Get human readable file reference information. | |
get_referencefileid () | |
get reference file id | |
get_referencelastsync () | |
Get reference last sync time. | |
get_referencelifetime () | |
Function stored_file\get_referencelifetime() is deprecated as reference life time is no longer stored in DB or returned by repository. | |
get_repository_id () | |
Returns repository id. | |
get_repository_type () | |
Returns repository type. | |
get_sortorder () | |
Returns the sort order of file. | |
get_source () | |
Returns the source of the file, usually it is a url. | |
get_status () | |
Returns file status flag. | |
get_timecreated () | |
Returns unix timestamp of file creation date. | |
get_timemodified () | |
Returns unix timestamp of last file modification. | |
get_total_content_size (file_packer $packer) | |
Returns the total size (in bytes) of the contents of an archive. | |
get_userid () | |
Returns id of user who created the file. | |
import_external_file_contents ($maxbytes=0) | |
Imports the contents of an external file into moodle filepool. | |
is_controlled_link () | |
Whether or not this is a controlled link. | |
is_directory () | |
Is this a directory? | |
is_external_file () | |
Whether or not this is a external resource. | |
is_valid_image () | |
Verifies the file is a valid web image - gif, png and jpeg only. | |
list_files (file_packer $packer) | |
List contents of archive. | |
readfile () | |
Dumps file content to page. | |
rename ($filepath, $filename) | |
Rename filename. | |
replace_content_with (stored_file $storedfile) | |
Function stored_file\replace_content_with() is deprecated. | |
replace_file_with (stored_file $newfile) | |
Replaces the fields that might have changed when file was overriden in filepicker: reference, contenthash, filesize, userid. | |
resize_image ($width, $height) | |
Generate a resized image for this stored_file. | |
rotate_image () | |
Generate a rotated image for this stored_file based on exif information. | |
send_file ($lifetime, $filter, $forcedownload, $options) | |
Send file references. | |
send_relative_file ($relativepath) | |
Gets a file relative to this file in the repository and sends it to the browser. | |
set_author ($author) | |
Set author. | |
set_filesize ($filesize) | |
Function stored_file\set_filesize() is deprecated. | |
set_license ($license) | |
Set license. | |
set_missingsource () | |
Sets the error status for a file that could not be synchronised. | |
set_sortorder ($sortorder) | |
Set file sort order. | |
set_source ($source) | |
Set license. | |
set_synchronised_content_from_file ($path) | |
Set synchronised content from file. | |
set_synchronised_content_from_string ($content) | |
Set synchronised content from content. | |
set_synchronized ($contenthash, $filesize, $status=0, $timemodified=null) | |
Called after reference-file has been synchronized with the repository. | |
set_timemodified ($timemodified) | |
set timemodified | |
sync_external_file () | |
Synchronize file if it is a reference and needs synchronizing. | |
Public Attributes | |
int const | FILE_HANDLE_FOPEN = 0 |
Indicates a file handle of the type returned by fopen. | |
int const | FILE_HANDLE_GZOPEN = 1 |
Indicates a file handle of the type returned by gzopen. | |
Protected Member Functions | |
update ($dataobject) | |
Update some file record fields NOTE: Must remain protected. | |
Class representing local files stored in a sha1 file pool.
Since Moodle 2.0 file contents are stored in sha1 pool and all other file information is stored in new "files" database table.
stored_file::__construct | ( | file_storage | $fs, |
stdClass | $file_record, | ||
$deprecated = null ) |
Constructor, this constructor should be called ONLY from the file_storage class!
file_storage | $fs | file storage instance |
stdClass | $file_record | description of file |
string | $deprecated |
stored_file::__sleep | ( | ) |
Magic method, called during serialization.
array |
stored_file::add_to_curl_request | ( | & | $curlrequest, |
$key ) |
adds this file path to a curl request (POST only)
curl | $curlrequest | the curl request object |
string | $key | what key to use in the POST request |
void |
stored_file::archive_file | ( | file_archive | $filearch, |
$archivepath ) |
Add file/directory into archive.
file_archive | $filearch | file archive instance |
string | $archivepath | pathname in archive |
bool | success |
stored_file::compare_to_path | ( | $path | ) |
Check whether the supplied file is the same as this file.
string | $path | The path to the file on disk |
boolean |
stored_file::compare_to_string | ( | $content | ) |
Check whether the supplied content is the same as this file.
string | $content | The file content |
boolean |
stored_file::copy_content_to | ( | $pathname | ) |
Copy content of file to given pathname.
string | $pathname | real path to the new file |
bool | success |
stored_file::copy_content_to_temp | ( | $dir = 'files', | |
$fileprefix = 'tempup_' ) |
Copy content of file to temporary folder and returns file path.
string | $dir | name of the temporary directory |
string | $fileprefix | prefix of temporary file. |
string|bool | path of temporary file or false. |
stored_file::delete | ( | ) |
Delete file from files table.
The content of files stored in sha1 pool is reclaimed later - the occupied disk space is reclaimed much later.
bool | always true or exception if error occurred |
stored_file::delete_reference | ( | ) |
Unlink the stored file from the referenced file.
This methods destroys the link to the record in files_reference table. This effectively turns the stored file from being an alias to a plain copy. However, the caller has to make sure that the actual file's content has beed synced prior to calling this method.
stored_file::extract_to_pathname | ( | file_packer | $packer, |
$pathname, | |||
file_progress | $progress = null ) |
Extract file to given file path (real OS filesystem), existing files are overwritten.
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 |
stored_file::extract_to_storage | ( | 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.
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 |
stored_file::generate_image_thumbnail | ( | $width, | |
$height ) |
Generates a thumbnail for this stored_file.
If the GD library has at least version 2 and PNG support is available, the returned data is the content of a transparent PNG file containing the thumbnail. Otherwise, the function returns contents of a JPEG file with black background containing the thumbnail.
int | $width | the width of the requested thumbnail |
int | $height | the height of the requested thumbnail |
string|bool | false if a problem occurs, the thumbnail image data otherwise |
stored_file::get_author | ( | ) |
Returns the author name of the file.
string |
stored_file::get_component | ( | ) |
Returns component name - this is the owner of the areas, nothing else is allowed to read or modify the files directly!!
string |
stored_file::get_content | ( | ) |
Returns file content as string.
string | content |
stored_file::get_content_file_handle | ( | $type = self::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.
int | $type | Type of file handle (FILE_HANDLE_xx constant) |
resource | file handle |
stored_file::get_contenthash | ( | ) |
Returns sha1 hash of file content.
string |
stored_file::get_contextid | ( | ) |
Returns context id of the file.
int | context id |
stored_file::get_filearea | ( | ) |
Returns file area name, this divides files of one component into groups with different access control.
All files in one area have the same access control.
string |
stored_file::get_filename | ( | ) |
Returns file name or '.
' in case of directories.
string |
stored_file::get_filepath | ( | ) |
Returns file path - starts and ends with /, are not allowed.
string |
stored_file::get_filesize | ( | ) |
Returns the size of file in bytes.
int | bytes |
stored_file::get_id | ( | ) |
Returns file id.
int |
stored_file::get_imageinfo | ( | ) |
Returns information about image, information is determined from the file content.
mixed | array with width, height and mimetype; false if not an image |
stored_file::get_itemid | ( | ) |
Returns returns item id of file.
int |
stored_file::get_license | ( | ) |
Returns the license type of the file, it is a short name referred from license table.
string |
stored_file::get_mimetype | ( | ) |
Returns mime type of file.
string |
stored_file::get_parent_directory | ( | ) |
Returns parent directory, creates missing parents if needed.
stored_file |
stored_file::get_pathnamehash | ( | ) |
Returns sha1 hash of all file path components sha1("contextid/component/filearea/itemid/dir/dir/filename.ext").
string |
stored_file::get_psr_stream | ( | ) |
Get a read-only PSR-7 stream for this file.
Note: This stream is read-only. If you want to modify the file, create a new file and delete the old one. The File API creates immutable files.
StreamInterface |
stored_file::get_reference | ( | ) |
Returns file reference.
string |
stored_file::get_reference_details | ( | ) |
Get human readable file reference information.
string |
stored_file::get_referencefileid | ( | ) |
get reference file id
int |
stored_file::get_referencelastsync | ( | ) |
Get reference last sync time.
int |
stored_file::get_referencelifetime | ( | ) |
Function stored_file\get_referencelifetime() is deprecated as reference life time is no longer stored in DB or returned by repository.
Each repository should decide by itself when to synchronise the references.
stored_file::get_repository_id | ( | ) |
Returns repository id.
int|null |
stored_file::get_repository_type | ( | ) |
Returns repository type.
mixed | str|null the repository type or null if is not an external file |
stored_file::get_sortorder | ( | ) |
Returns the sort order of file.
int |
stored_file::get_source | ( | ) |
Returns the source of the file, usually it is a url.
string |
stored_file::get_status | ( | ) |
Returns file status flag.
int | 0 means file OK, anything else is a problem and file can not be used |
stored_file::get_timecreated | ( | ) |
Returns unix timestamp of file creation date.
int |
stored_file::get_timemodified | ( | ) |
Returns unix timestamp of last file modification.
int |
stored_file::get_total_content_size | ( | file_packer | $packer | ) |
Returns the total size (in bytes) of the contents of an archive.
file_packer | $packer | file packer instance |
int|null | total size in bytes |
stored_file::get_userid | ( | ) |
Returns id of user who created the file.
int |
stored_file::import_external_file_contents | ( | $maxbytes = 0 | ) |
Imports the contents of an external file into moodle filepool.
moodle_exception | if file could not be downloaded or is too big |
int | $maxbytes | throw an exception if file size is bigger than $maxbytes (0 means no limit) |
stored_file::is_controlled_link | ( | ) |
Whether or not this is a controlled link.
Note that repositories cannot support FILE_REFERENCE and FILE_CONTROLLED_LINK.
bool |
stored_file::is_directory | ( | ) |
Is this a directory?
Directories are only emulated, internally they are stored as empty files with a "." instead of name - this means empty directory contains exactly one empty file with name dot.
bool | true means directory, false means file |
stored_file::is_external_file | ( | ) |
Whether or not this is a external resource.
bool |
stored_file::is_valid_image | ( | ) |
Verifies the file is a valid web image - gif, png and jpeg only.
It should be ok to serve this image from server without any other security workarounds.
bool | true if file ok |
stored_file::list_files | ( | file_packer | $packer | ) |
List contents of archive.
file_packer | $packer | file packer instance |
array | of file infos |
stored_file::rename | ( | $filepath, | |
$filename ) |
Rename filename.
string | $filepath | file path |
string | $filename | file name |
stored_file::replace_content_with | ( | stored_file | $storedfile | ) |
Function stored_file\replace_content_with() is deprecated.
Please use stored_file\replace_file_with()
stored_file::replace_file_with | ( | stored_file | $newfile | ) |
Replaces the fields that might have changed when file was overriden in filepicker: reference, contenthash, filesize, userid.
Note that field 'source' must be updated separately because it has different format for draft and non-draft areas and this function will usually be used to replace non-draft area file with draft area file.
stored_file | $newfile |
coding_exception |
stored_file::resize_image | ( | $width, | |
$height ) |
Generate a resized image for this stored_file.
int | null | $width | The desired width, or null to only use the height. |
int | null | $height | The desired height, or null to only use the width. |
string|false | False when a problem occurs, else the image data. |
stored_file::rotate_image | ( | ) |
Generate a rotated image for this stored_file based on exif information.
array|false | False when a problem occurs, else the image data and image size. |
stored_file::send_file | ( | $lifetime, | |
$filter, | |||
$forcedownload, | |||
$options ) |
Send file references.
int | $lifetime | Number of seconds before the file should expire from caches (default 24 hours) |
int | $filter | 0 (default)=no filtering, 1=all files, 2=html files only |
bool | $forcedownload | If true (default false), forces download of file rather than view in browser/plugin |
array | $options | additional options affecting the file serving |
stored_file::send_relative_file | ( | $relativepath | ) |
Gets a file relative to this file in the repository and sends it to the browser.
Checks the function repository\supports_relative_file() to make sure it can be used.
string | $relativepath | the relative path to the file we are trying to access |
stored_file::set_author | ( | $author | ) |
Set author.
string | $author |
stored_file::set_filesize | ( | $filesize | ) |
Function stored_file\set_filesize() is deprecated.
Please use stored_file\replace_file_with
stored_file::set_license | ( | $license | ) |
Set license.
string | $license | license |
stored_file::set_sortorder | ( | $sortorder | ) |
Set file sort order.
int | $sortorder |
int |
stored_file::set_source | ( | $source | ) |
Set license.
string | $license | license |
stored_file::set_synchronised_content_from_file | ( | $path | ) |
Set synchronised content from file.
string | $path | Path to the file. |
stored_file::set_synchronised_content_from_string | ( | $content | ) |
Set synchronised content from content.
string | $content | File content. |
stored_file::set_synchronized | ( | $contenthash, | |
$filesize, | |||
$status = 0, | |||
$timemodified = null ) |
Called after reference-file has been synchronized with the repository.
We update contenthash, filesize and status in files table if changed and we always update lastsync in files_reference table
null | string | $contenthash | if set to null contenthash is not changed |
int | $filesize | new size of the file |
int | $status | new status of the file (0 means OK, 666 - source missing) |
int | $timemodified | last time modified of the source, if known |
stored_file::set_timemodified | ( | $timemodified | ) |
set timemodified
int | $timemodified |
stored_file::sync_external_file | ( | ) |
Synchronize file if it is a reference and needs synchronizing.
Updates contenthash and filesize
|
protected |
Update some file record fields NOTE: Must remain protected.
stdClass | $dataobject |