Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
|
Namespaces | |
namespace | core |
| |
namespace | core_files |
| |
namespace | core_files\external |
| |
namespace | core_files\external\delete |
| |
namespace | core_files\external\get |
| |
namespace | core_files\local\archive_writer |
| |
namespace | core_files\privacy |
| |
namespace | core_files\reportbuilder\datasource |
| |
namespace | core_files\reportbuilder\local\entities |
| |
namespace | core_files\task |
| |
Classes | |
class | core\content |
The Content API allows all parts of Moodle to determine details about content within a component, or plugintype. More... | |
class | core_files\archive_writer |
Each file archive type must extend this class. More... | |
class | core_files\conversion |
Class representing a conversion currently in progress. More... | |
class | core_files\converter |
Class for converting files between different formats using unoconv. More... | |
interface | core_files\converter_interface |
Class for converting files between different file formats. More... | |
class | core_files\external\delete\draft |
This is the external method for deleting draft files. More... | |
class | core_files\external\get\unused_draft |
Generate a new draft itemid for the current user. More... | |
class | core_files\external\stored_file_exporter |
interface | core_files\local\archive_writer\file_writer_interface |
Interface used by archives that write to files. More... | |
interface | core_files\local\archive_writer\stream_writer_interface |
Interface used by archives that write to streams. More... | |
class | core_files\local\archive_writer\zip_writer |
Class used for creating ZIP archives. More... | |
class | core_files\privacy\provider |
Data provider class. More... | |
class | core_files\reportbuilder\datasource\files |
class | core_files\reportbuilder\local\entities\file |
class | core_files\task\conversion_cleanup_task |
A scheduled task to clear up old conversion records. More... | |
class | core_files_external |
Files external functions. More... | |
class | core_form\privacy\provider |
Implements the privacy API for the core_form subsystem. More... | |
class | curl |
RESTful cURL class. More... | |
class | curl_cache |
This class is used by cURL class, use case: More... | |
class | file_access_exception |
No file access exception. More... | |
class | file_archive |
Each file archive type must extend this class. More... | |
class | file_browser |
This class provides the main entry point for other code wishing to get information about files. More... | |
class | file_exception |
Basic file related exception class. More... | |
class | file_info |
Base class for things in the tree navigated by file_browser. More... | |
class | file_info_area_backup_section |
Implementation of course section backup area. More... | |
class | file_info_area_course_legacy |
Subclass of file_info_stored for files in the course files area. More... | |
class | file_info_area_course_section |
Represents a course category context in the tree navigated by file_browser. More... | |
class | file_info_context_course |
Represents a course context in the tree navigated by file_browser. More... | |
class | file_info_context_coursecat |
Represents a course category context in the tree navigated by file_browser. More... | |
class | file_info_context_module |
Represents a module context in the tree navigated by file_browser. More... | |
class | file_info_context_system |
Represents the system context in the tree navigated by file_browser. More... | |
class | file_info_context_user |
Represents a user context in the tree navigated by file_browser. More... | |
class | file_info_stored |
Represents an actual file or folder - a row in the file table in the tree navigated by file_browser. More... | |
class | file_packer |
Abstract class for archiving of files. More... | |
class | file_pool_content_exception |
Hash file content problem exception. More... | |
interface | file_progress |
class | file_reference_exception |
Problem with records in the {files_reference} table. More... | |
class | file_storage |
File storage class used for low level access to stored files. More... | |
class | file_system |
class | file_system_filedir |
File system class used for low level access to real files in filedir. More... | |
class | mbz_packer |
Utility class - handles all packing/unpacking of .mbz files. More... | |
class | stored_file |
Class representing local files stored in a sha1 file pool. More... | |
class | stored_file_creation_exception |
Cannot create file exception. More... | |
class | tgz_extractor |
Extracts .tar.gz files (POSIX format). More... | |
interface | tgz_extractor_handler |
Interface for callback from tgz_extractor\extract. More... | |
class | tgz_packer |
Utility class - handles all packing/unpacking of .tar.gz files. More... | |
class | tgz_packer_extract_to_pathname |
Handles extraction to pathname. More... | |
class | tgz_packer_extract_to_storage |
Handles extraction to file storage. More... | |
class | virtual_root_file |
Represents the root directory of an empty file area in the tree navigated by file_browser. More... | |
class | zip_archive |
Zip file archive class. More... | |
class | zip_packer |
Utility class - handles all zipping and unzipping operations. More... | |
Functions | |
byteserving_send_file ($handle, $mimetype, $ranges, $filesize) | |
Send requested byterange of file. | |
download_file_content ($url, $headers=null, $postdata=null, $fullresponse=false, $timeout=300, $connecttimeout=20, $skipcertverify=false, $tofile=NULL, $calctimeout=false) | |
Fetches content of file from Internet (using proxy if defined). | |
file_area_contains_subdirs (context $context, $component, $filearea, $itemid) | |
Detects if area contains subdirs, this is intended for file areas that are attached to content migrated from 1.x where subdirs were allowed everywhere. | |
file_copy_file_to_file_area ($file, $filename, $itemid) | |
Copies a file from one file area to another. | |
file_correct_filepath ($str) | |
Convert any string to a valid filepath. | |
stdClass | file_encode_url ($urlbase, $path, $forcedownload=false, $https=false) |
Encodes file serving url. | |
file_extension_icon ($filename, $unused=null) | |
Returns the relative icon path for a given file name. | |
file_extension_in_typegroup ($filename, $groups, $checktype=false) | |
Checks if file with name $filename has one of the extensions in groups $groups. | |
file_file_icon ($file, $unused=null) | |
Return the relative icon path for a given file. | |
file_folder_icon ($unused=null) | |
Return the relative icon path for a folder image. | |
file_get_all_files_in_draftarea (int $draftitemid, string $filepath='/') | |
Returns all of the files in the draftarea. | |
file_get_drafarea_files ($draftitemid, $filepath='/') | |
Listing all files (including folders) in current path (draft area) used by file manager. | |
file_get_drafarea_folders ($draftitemid, $filepath, &$data) | |
Generate a folder tree of draft area of current USER recursively. | |
stdClass | file_get_draft_area_info ($draftitemid, $filepath='/') |
Returns information about files in a draft area. | |
file_get_file_area_info ($contextid, $component, $filearea, $itemid=0, $filepath='/') | |
Returns information about files in an area. | |
file_get_submitted_draft_itemid ($elname) | |
Returns draft area itemid for a given element. | |
file_get_typegroup ($element, $groups) | |
Returns array of elements of type $element in type group(s) | |
moodle_database | file_get_unused_draft_itemid () |
Generate a draft itemid. | |
file_get_upload_error ($errorcode) | |
Returns description of upload error. | |
moodle_database | file_get_user_used_space () |
Get used space of files $DB @global stdClass $USER. | |
file_is_draft_area_limit_reached ($draftitemid, $areamaxbytes, $newfilesize=0, $includereferences=false) | |
Returns whether a draft area has exceeded/will exceed its size limit. | |
file_is_draft_areas_limit_reached (int $userid) | |
Returns whether a user has reached their draft area upload rate. | |
file_is_executable ($filename) | |
Tells whether the filename is executable. | |
file_is_svg_image_from_mimetype (string $mimetype) | |
Attempt to determine whether the specified mime-type is an SVG image or not. | |
file_merge_draft_area_into_draft_area ($getfromdraftid, $mergeintodraftid) | |
Merge files from two draftarea areas. | |
file_merge_draft_areas ($draftitemid, $usercontextid, $text, $forcehttps=false) | |
Finds all draft areas used in a textarea and copies the files into the primary textarea. | |
file_merge_files_from_draft_area_into_filearea ($draftitemid, $contextid, $component, $filearea, $itemid, array $options=null) | |
Add files from a draft area into a final area. | |
file_mimetype_icon ($mimetype, $unused=null) | |
Returns the relative icon path for a given mime type. | |
file_mimetype_in_typegroup ($mimetype, $groups) | |
Checks if mimetype $mimetype belongs to one of the groups $groups. | |
file_overwrite_existing_draftfile (stored_file $newfile, stored_file $existingfile) | |
Overwrite an existing file in a draft area. | |
file_pluginfile ($relativepath, $forcedownload, $preview=null, $offline=false, $embed=false) | |
This function delegates file serving to individual plugins. | |
file_postupdate_standard_editor ($data, $field, array $options, $context, $component=null, $filearea=null, $itemid=null) | |
Prepares the content of the 'editor' form element with embedded media files to be saved in database. | |
file_postupdate_standard_filemanager ($data, $field, array $options, $context, $component, $filearea, $itemid) | |
Saves files modified by File manager formslib element. | |
stdClass | file_prepare_draft_area (&$draftitemid, $contextid, $component, $filearea, $itemid, array $options=null, $text=null) |
Initialise a draft file area from a real one by copying the files. | |
file_prepare_standard_editor ($data, $field, array $options, $context=null, $component=null, $filearea=null, $itemid=null) | |
Prepares 'editor' formslib element from data in database. | |
file_prepare_standard_filemanager ($data, $field, array $options, $context=null, $component=null, $filearea=null, $itemid=null) | |
Saves text and files modified by Editor formslib element. | |
file_remove_editor_orphaned_files ($editor) | |
Removes those files from the user drafts filearea which are not referenced in the editor text. | |
file_replace_file_area_in_text ($file, $newid, $text, $forcehttps=false) | |
Rewrites a file area in arbitrary text. | |
moodle_database | file_reset_sortorder ($contextid, $component, $filearea, $itemid=false) |
reset file sort order number to 0 $DB | |
file_restore_source_field_from_draft_file ($storedfile) | |
Restore the original source field from draft files. | |
file_rewrite_pluginfile_urls ($text, $file, $contextid, $component, $filearea, $itemid, array $options=null) | |
Convert encoded URLs in $text from the @PLUGINFILE@/... form to an actual URL. | |
file_rewrite_urls_to_pluginfile ($text, $draftitemid, $forcehttps=false) | |
Convert the draft file area URLs in some content to @PLUGINFILE@ tokens ready to be saved in the database. | |
file_safe_save_content ($content, $destination) | |
Safely save content to a certain path. | |
stdClass | file_save_draft_area_files ($draftitemid, $contextid, $component, $filearea, $itemid, array $options=null, $text=null, $forcehttps=false) |
Saves files from a draft file area to a real one (merging the list of files). | |
moodle_database | file_set_sortorder ($contextid, $component, $filearea, $itemid, $filepath, $filename, $sortorder) |
Set file sort order. | |
format_array_postdata_for_curlcall ($arraydata, $currentdata, &$data) | |
Recursive function formating an array in POST parameter. | |
format_postdata_for_curlcall ($postdata) | |
Transform a PHP array into POST parameter (see the recursive function format_array_postdata_for_curlcall) | |
fulldelete ($location) | |
Recursively delete the file or folder with path $location. | |
get_mimetype_description ($obj, $capitalise=false) | |
Obtains descriptions for file types (e.g. | |
get_mimetype_for_sending ($filename='') | |
Determine a file's MIME type based on the given filename using the function mimeinfo. | |
& | get_mimetypes_array () |
Returns a list of information about file types based on extensions. | |
get_moodle_proxy_url () | |
Returns the moodle proxy configuration as a formatted url. | |
mimeinfo ($element, $filename) | |
Obtains information about a filetype based on its extension. | |
mimeinfo_from_type ($element, $mimetype) | |
Obtains information about a filetype based on the MIME type rather than the other way around. | |
readfile_accel ($file, $mimetype, $accelerate) | |
Enhanced readfile() with optional acceleration. | |
readfile_allow_large ($path, $filesize=-1) | |
The readfile function can fail when files are larger than 2GB (even on 64-bit platforms). | |
readstring_accel ($string, $mimetype, $accelerate=false) | |
Similar to readfile_accel() but designed for strings. | |
send_content_uncached ($content, $filename) | |
Serve content which is not meant to be cached. | |
send_file ($path, $filename, $lifetime=null, $filter=0, $pathisstring=false, $forcedownload=false, $mimetype='', $dontdie=false, array $options=array()) | |
Handles the sending of file data to the user's browser, including support for byteranges etc. | |
stdClass | send_file_not_found () |
Requested file is not found or not accessible, does not return, terminates script. | |
send_header_404 () | |
Helper function to send correct 404 for server. | |
send_stored_file ($storedfile, $lifetime=null, $filter=0, $forcedownload=false, array $options=array()) | |
Handles the sending of file data to the user's browser, including support for byteranges etc. | |
send_temp_file ($path, $filename, $pathisstring=false) | |
Handles the sending of temporary file to user, download is forced. | |
send_temp_file_finished ($path) | |
Internal callback function used by send_temp_file() | |
byteserving_send_file | ( | $handle, | |
$mimetype, | |||
$ranges, | |||
$filesize ) |
Send requested byterange of file.
resource | $handle | A file handle |
string | $mimetype | The mimetype for the output |
array | $ranges | An array of ranges to send |
string | $filesize | The size of the content if only one range is used |
download_file_content | ( | $url, | |
$headers = null, | |||
$postdata = null, | |||
$fullresponse = false, | |||
$timeout = 300, | |||
$connecttimeout = 20, | |||
$skipcertverify = false, | |||
$tofile = NULL, | |||
$calctimeout = false ) |
Fetches content of file from Internet (using proxy if defined).
Uses cURL extension if present. Due to security concerns only downloads from http(s) sources are supported.
string | $url | file url starting with http(s):// |
array | $headers | http headers, null if none. If set, should be an associative array of header name => value pairs. |
array | $postdata | array means use POST request with given parameters |
bool | $fullresponse | return headers, responses, etc in a similar way snoopy does (if false, just returns content) |
int | $timeout | timeout for complete download process including all file transfer (default 5 minutes) |
int | $connecttimeout | timeout for connection to server; this is the timeout that usually happens if the remote server is completely down (default 20 seconds); may not work when using proxy |
bool | $skipcertverify | If true, the peer's SSL certificate will not be checked. Only use this when already in a trusted location. |
string | $tofile | store the downloaded content to file instead of returning it. |
bool | $calctimeout | false by default, true enables an extra head request to try and determine filesize and appropriately larger timeout based on $CFG->curltimeoutkbitrate |
stdClass|string|bool | stdClass object if $fullresponse is true, false if request failed, true if file downloaded into $tofile successfully or the file content as a string. |
file_area_contains_subdirs | ( | context | $context, |
$component, | |||
$filearea, | |||
$itemid ) |
Detects if area contains subdirs, this is intended for file areas that are attached to content migrated from 1.x where subdirs were allowed everywhere.
context | $context | |
string | $component | |
string | $filearea | |
string | $itemid |
bool |
file_copy_file_to_file_area | ( | $file, | |
$filename, | |||
$itemid ) |
Copies a file from one file area to another.
array | $file | Information about the file to be copied. |
string | $filename | The filename. |
int | $itemid | The new file area. |
file_correct_filepath | ( | $str | ) |
Convert any string to a valid filepath.
string | $str |
string | path |
stdClass file_encode_url | ( | $urlbase, | |
$path, | |||
$forcedownload = false, | |||
$https = false ) |
Encodes file serving url.
string | $urlbase | |
string | $path | /filearea/itemid/dir/dir/file.exe |
bool | $forcedownload | |
bool | $https | https url required |
string | encoded file url |
file_extension_icon | ( | $filename, | |
$unused = null ) |
Returns the relative icon path for a given file name.
This function should be used in conjunction with $OUTPUT->image_url to produce a return the full path to an icon.
$filename = '.jpg'; $icon = $OUTPUT->image_url(file_extension_icon($filename))->out(); echo html_writer\empty_tag('img', array('src' => $icon, 'alt' => '...'));
MDL-31074 When an $OUTPUT->icon method is available this function should be altered to conform with that.
MDL-31074 Implement $size
string | $filename | The filename to get the icon for |
mixed | $unused | This parameter has been deprecated since 4.3 and should not be used anymore. |
string |
file_extension_in_typegroup | ( | $filename, | |
$groups, | |||
$checktype = false ) |
Checks if file with name $filename has one of the extensions in groups $groups.
string | $filename | name of the file to check |
string | array | $groups | one group or array of groups to check |
bool | $checktype | if true and extension check fails, find the mimetype and check if file mimetype is in mimetypes in groups $groups |
bool |
file_file_icon | ( | $file, | |
$unused = null ) |
Return the relative icon path for a given file.
Usage: // $file - instance of stored_file or file_info $icon = $OUTPUT->image_url(file_file_icon($file))->out(); echo html_writer\empty_tag('img', array('src' => $icon, 'alt' => get_mimetype_description($file)));
or echo $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file));
stored_file | file_info | stdClass | array | $file | (in case of object attributes $file->filename and $file->mimetype are expected) |
mixed | $unused | This parameter has been deprecated since 4.3 and should not be used anymore. |
string |
file_folder_icon | ( | $unused = null | ) |
Return the relative icon path for a folder image.
Usage: $icon = $OUTPUT->image_url(file_folder_icon())->out(); echo html_writer\empty_tag('img', array('src' => $icon));
or echo $OUTPUT->pix_icon(file_folder_icon(), '');
mixed | $unused | This parameter has been deprecated since 4.3 and should not be used anymore. |
string |
file_get_all_files_in_draftarea | ( | int | $draftitemid, |
string | $filepath = '/' ) |
Returns all of the files in the draftarea.
int | $draftitemid | The draft item ID |
string | $filepath | path for the uploaded files. |
array | An array of files associated with this draft item id. |
file_get_drafarea_files | ( | $draftitemid, | |
$filepath = '/' ) |
Listing all files (including folders) in current path (draft area) used by file manager.
int | $draftitemid | |
string | $filepath |
stdClass |
file_get_drafarea_folders | ( | $draftitemid, | |
$filepath, | |||
& | $data ) |
stdClass file_get_draft_area_info | ( | $draftitemid, | |
$filepath = '/' ) |
Returns information about files in a draft area.
$CFG @global stdClass $USER
int | $draftitemid | the draft area item id. |
string | $filepath | path to the directory from which the information have to be retrieved. |
array | with the following entries: 'filecount' => number of files in the draft area. 'filesize' => total size of the files in the draft area. 'foldercount' => number of folders in the draft area. 'filesize_without_references' => total size of the area excluding file references. (more information will be added as needed). |
file_get_file_area_info | ( | $contextid, | |
$component, | |||
$filearea, | |||
$itemid = 0, | |||
$filepath = '/' ) |
Returns information about files in an area.
int | $contextid | context id |
string | $component | component |
string | $filearea | file area name |
int | $itemid | item id or all files if not specified |
string | $filepath | path to the directory from which the information have to be retrieved. |
array | with the following entries: 'filecount' => number of files in the area. 'filesize' => total size of the files in the area. 'foldercount' => number of folders in the area. 'filesize_without_references' => total size of the area excluding file references. |
file_get_submitted_draft_itemid | ( | $elname | ) |
Returns draft area itemid for a given element.
string | $elname | name of formlib editor element, or a hidden form field that stores the draft area item id, etc. |
int | the itemid, or 0 if there is not one yet. |
file_get_typegroup | ( | $element, | |
$groups ) |
Returns array of elements of type $element in type group(s)
string | $element | name of the element we are interested in, usually 'type' or 'extension' |
string | array | $groups | one group or array of groups/extensions/mimetypes |
array |
moodle_database file_get_unused_draft_itemid | ( | ) |
Generate a draft itemid.
$DB @global stdClass $USER
int | a random but available draft itemid that can be used to create a new draft file area. |
file_get_upload_error | ( | $errorcode | ) |
Returns description of upload error.
int | $errorcode | found in $_FILES['filename.ext']['error'] |
string | error description string, '' if ok |
moodle_database file_get_user_used_space | ( | ) |
Get used space of files $DB @global stdClass $USER.
int | total bytes |
file_is_draft_area_limit_reached | ( | $draftitemid, | |
$areamaxbytes, | |||
$newfilesize = 0, | |||
$includereferences = false ) |
Returns whether a draft area has exceeded/will exceed its size limit.
Please note that the unlimited value for $areamaxbytes is -1 FILE_AREA_MAX_BYTES_UNLIMITED, not 0.
int | $draftitemid | the draft area item id. |
int | $areamaxbytes | the maximum size allowed in this draft area. |
int | $newfilesize | the size that would be added to the current area. |
bool | $includereferences | true to include the size of the references in the area size. |
bool | true if the area will/has exceeded its limit. |
file_is_draft_areas_limit_reached | ( | int | $userid | ) |
Returns whether a user has reached their draft area upload rate.
int | $userid | The user id |
bool |
file_is_executable | ( | $filename | ) |
Tells whether the filename is executable.
@externalurl http://php.net/manual/en/function.is-executable.php @externalurl https://bugs.php.net/bug.php?id=41062
string | $filename | Path to the file. |
bool | True if the filename exists and is executable; otherwise, false. |
file_is_svg_image_from_mimetype | ( | string | $mimetype | ) |
Attempt to determine whether the specified mime-type is an SVG image or not.
string | $mimetype | Mime-type |
bool | True if it is an SVG file |
file_merge_draft_area_into_draft_area | ( | $getfromdraftid, | |
$mergeintodraftid ) |
Merge files from two draftarea areas.
This does not handle conflict resolution, files in the destination area which appear to be more recent will be kept disregarding the intended ones.
int | $getfromdraftid | the id of the draft area where are the files to merge. |
int | $mergeintodraftid | the id of the draft area where new files will be merged. |
coding_exception |
file_merge_draft_areas | ( | $draftitemid, | |
$usercontextid, | |||
$text, | |||
$forcehttps = false ) |
Finds all draft areas used in a textarea and copies the files into the primary textarea.
If a user copies and pastes content from another draft area it's possible for a single textarea to reference multiple draft areas.
int | $draftitemid | the id of the primary draft area. When set to -1 (probably, by a WebService) it won't process file merging, keeping the original state of the file area. |
int | $usercontextid | the user's context id. |
string | $text | some html content that needs to have files copied to the correct draft area. |
bool | $forcehttps | force https urls. |
string\$text | html content modified with new draft links |
file_merge_files_from_draft_area_into_filearea | ( | $draftitemid, | |
$contextid, | |||
$component, | |||
$filearea, | |||
$itemid, | |||
array | $options = null ) |
Add files from a draft area into a final area.
Most of the time you do not want to use this. It is intended to be used by asynchronous services which cannot direcly manipulate a final area through a draft area. Instead they add files to a new draft area and merge that new draft into the final area when ready.
int | $draftitemid | the id of the draft area to use. |
int | $contextid | this parameter and the next two identify the file area to save to. |
string | $component | component name |
string | $filearea | indentifies the file area |
int | $itemid | identifies the item id or false for all items in the file area |
array | $options | area options (subdirs=false, maxfiles=-1, maxbytes=0, areamaxbytes=FILE_AREA_MAX_BYTES_UNLIMITED) |
file_mimetype_icon | ( | $mimetype, | |
$unused = null ) |
Returns the relative icon path for a given mime type.
This function should be used in conjunction with $OUTPUT->image_url to produce a return the full path to an icon.
$mimetype = 'image/jpg'; $icon = $OUTPUT->image_url(file_mimetype_icon($mimetype))->out(); echo html_writer\empty_tag('img', array('src' => $icon, 'alt' => get_mimetype_description($mimetype)));
string | $mimetype | The mimetype to fetch an icon for |
mixed | $unused | This parameter has been deprecated since 4.3 and should not be used anymore. |
string | The relative path to the icon |
file_mimetype_in_typegroup | ( | $mimetype, | |
$groups ) |
Checks if mimetype $mimetype belongs to one of the groups $groups.
string | $mimetype | |
string | array | $groups | one group or array of groups to check |
bool |
file_overwrite_existing_draftfile | ( | stored_file | $newfile, |
stored_file | $existingfile ) |
Overwrite an existing file in a draft area.
stored_file | $newfile | the new file with the new content and meta-data |
stored_file | $existingfile | the file that will be overwritten |
moodle_exception |
file_pluginfile | ( | $relativepath, | |
$forcedownload, | |||
$preview = null, | |||
$offline = false, | |||
$embed = false ) |
This function delegates file serving to individual plugins.
string | $relativepath | |
bool | $forcedownload | |
null | string | $preview | the preview mode, defaults to serving the original file |
boolean | $offline | If offline is requested - don't serve a redirect to an external file, return a file suitable for viewing offline (e.g. mobile app). |
bool | $embed | Whether this file will be served embed into an iframe. |
file_postupdate_standard_editor | ( | $data, | |
$field, | |||
array | $options, | ||
$context, | |||
$component = null, | |||
$filearea = null, | |||
$itemid = null ) |
Prepares the content of the 'editor' form element with embedded media files to be saved in database.
This function moves files from draft area to the destination area and encodes URLs to the draft files so they can be safely saved into DB. The form has to contain the 'editor' element named foobar_editor, where 'foobar' is the name of the database field to hold the wysiwyg editor content. The editor data comes as an array with text, format and itemid properties. This function automatically adds $data properties foobar, foobarformat and foobartrust, where foobar has URL to embedded files encoded.
stdClass | $data | raw data submitted by the form |
string | $field | name of the database field containing the html with embedded media files |
array | $options | editor options (trusttext, subdirs, maxfiles, maxbytes etc.) |
stdClass | $context | context, required for existing data |
string | $component | file component |
string | $filearea | file area name |
int | $itemid | item id, required if item exists |
stdClass | modified data object |
file_postupdate_standard_filemanager | ( | $data, | |
$field, | |||
array | $options, | ||
$context, | |||
$component, | |||
$filearea, | |||
$itemid ) |
Saves files modified by File manager formslib element.
stdClass | $data | $database entry field |
string | $field | name of data field |
array | $options | various options |
stdClass | $context | context - must already exist |
string | $component | |
string | $filearea | file area name |
int | $itemid | must already exist, usually means data is in db |
stdClass | modified data obejct |
stdClass file_prepare_draft_area | ( | & | $draftitemid, |
$contextid, | |||
$component, | |||
$filearea, | |||
$itemid, | |||
array | $options = null, | ||
$text = null ) |
Initialise a draft file area from a real one by copying the files.
A draft area will be created if one does not already exist. Normally you should get $draftitemid by calling file_get_submitted_draft_itemid('elementname');
$CFG @global stdClass $USER
int | $draftitemid | the id of the draft area to use, or 0 to create a new one, in which case this parameter is updated. |
int | $contextid | This parameter and the next two identify the file area to copy files from. |
string | $component | |
string | $filearea | helps indentify the file area. |
int | $itemid | helps identify the file area. Can be null if there are no files yet. |
array | $options | text and file options ('subdirs'=>false, 'forcehttps'=>false) |
string | $text | some html content that needs to have embedded links rewritten to point to the draft area. |
string|null | returns string if $text was passed in, the rewritten $text is returned. Otherwise NULL. |
file_prepare_standard_editor | ( | $data, | |
$field, | |||
array | $options, | ||
$context = null, | |||
$component = null, | |||
$filearea = null, | |||
$itemid = null ) |
Prepares 'editor' formslib element from data in database.
The passed $data record must contain field foobar, foobarformat and optionally foobartrust. This function then copies the embedded files into draft area (assigning itemids automatically), creates the form element foobar_editor and rewrites the URLs so the embedded images can be displayed. In your mform definition, you must have an 'editor' element called foobar_editor. Then you call your mform's set_data() supplying the object returned by this function.
stdClass | $data | database field that holds the html text with embedded media |
string | $field | the name of the database field that holds the html text with embedded media |
array | $options | editor options (like maxifiles, maxbytes etc.) |
stdClass | $context | context of the editor |
string | $component | |
string | $filearea | file area name |
int | $itemid | item id, required if item exists |
stdClass | modified data object |
file_prepare_standard_filemanager | ( | $data, | |
$field, | |||
array | $options, | ||
$context = null, | |||
$component = null, | |||
$filearea = null, | |||
$itemid = null ) |
Saves text and files modified by Editor formslib element.
stdClass | $data | $database entry field |
string | $field | name of data field |
array | $options | various options |
stdClass | $context | context - must already exist |
string | $component | |
string | $filearea | file area name |
int | $itemid | must already exist, usually means data is in db |
stdClass | modified data obejct |
file_remove_editor_orphaned_files | ( | $editor | ) |
Removes those files from the user drafts filearea which are not referenced in the editor text.
array | $editor | The online text editor element from the submitted form data. |
file_replace_file_area_in_text | ( | $file, | |
$newid, | |||
$text, | |||
$forcehttps = false ) |
Rewrites a file area in arbitrary text.
array | $file | General information about the file. |
int | $newid | The new file area itemid. |
string | $text | The text to rewrite. |
bool | $forcehttps | force https urls. |
string | The rewritten text. |
moodle_database file_reset_sortorder | ( | $contextid, | |
$component, | |||
$filearea, | |||
$itemid = false ) |
reset file sort order number to 0 $DB
int | $contextid | the context id |
string | $component | |
string | $filearea | file area. |
int | bool | $itemid | itemid. |
bool |
file_restore_source_field_from_draft_file | ( | $storedfile | ) |
Restore the original source field from draft files.
Do not use this function because it makes field files.source inconsistent for draft area files. This function will be deprecated in 2.6
stored_file | $storedfile | This only works with draft files |
stored_file |
file_rewrite_pluginfile_urls | ( | $text, | |
$file, | |||
$contextid, | |||
$component, | |||
$filearea, | |||
$itemid, | |||
array | $options = null ) |
Convert encoded URLs in $text from the @PLUGINFILE@/... form to an actual URL.
Passing a new option reverse = true in the $options var will make the function to convert actual URLs in $text to encoded URLs in the @PLUGINFILE@ form.
string | $text | The content that may contain ULRs in need of rewriting. |
string | $file | The script that should be used to serve these files. pluginfile.php, draftfile.php, etc. |
int | $contextid | This parameter and the next two identify the file area to use. |
string | $component | |
string | $filearea | helps identify the file area. |
?int | $itemid | helps identify the file area. |
array | $options | bool $options.forcehttps Force the user of https bool $options.reverse Reverse the behaviour of the function mixed $options.includetoken Use a token for authentication. True for current user, int value for other user id. string The processed text. |
file_rewrite_urls_to_pluginfile | ( | $text, | |
$draftitemid, | |||
$forcehttps = false ) |
Convert the draft file area URLs in some content to @PLUGINFILE@ tokens ready to be saved in the database.
Normally, this is done automatically by file_save_draft_area_files().
string | $text | the content to process. |
int | $draftitemid | the draft file area the content was using. |
bool | $forcehttps | whether the content contains https URLs. Default false. |
string | the processed content. |
file_safe_save_content | ( | $content, | |
$destination ) |
Safely save content to a certain path.
This function tries hard to be atomic by first copying the content to a separate file, and then moving the file across. It also prevents the user to abort a request to prevent half-safed files.
This function is intended to be used when saving some content to cache like $CFG->localcachedir. If you're not caching a file you should use the File API.
string | $content | The file content. |
string | $destination | The absolute path of the final file. |
void |
stdClass file_save_draft_area_files | ( | $draftitemid, | |
$contextid, | |||
$component, | |||
$filearea, | |||
$itemid, | |||
array | $options = null, | ||
$text = null, | |||
$forcehttps = false ) |
Saves files from a draft file area to a real one (merging the list of files).
Can rewrite URLs in some content at the same time if desired.
$USER
int | $draftitemid | the id of the draft area to use. Normally obtained from file_get_submitted_draft_itemid('elementname') or similar. When set to -1 (probably, by a WebService) it won't process file merging, keeping the original state of the file area. |
int | $contextid | This parameter and the next two identify the file area to save to. |
string | $component | |
string | $filearea | indentifies the file area. |
int | $itemid | helps identifies the file area. |
array | $options | area options (subdirs=>false, maxfiles=-1, maxbytes=0) |
string | $text | some html content that needs to have embedded links rewritten to the @PLUGINFILE@ form for saving in the database. |
bool | $forcehttps | force https urls. |
string|null | if $text was passed in, the rewritten $text is returned. Otherwise NULL. |
moodle_database file_set_sortorder | ( | $contextid, | |
$component, | |||
$filearea, | |||
$itemid, | |||
$filepath, | |||
$filename, | |||
$sortorder ) |
Set file sort order.
$DB
int | $contextid | the context id |
string | $component | file component |
string | $filearea | file area. |
int | $itemid | itemid. |
string | $filepath | file path. |
string | $filename | file name. |
int | $sortorder | the sort order of file. |
bool |
format_array_postdata_for_curlcall | ( | $arraydata, | |
$currentdata, | |||
& | $data ) |
Recursive function formating an array in POST parameter.
array | $arraydata | - the array that we are going to format and add into &$data array |
string | $currentdata | - a row of the final postdata array at instant T when finish, it's assign to $data under this format: name[keyname][][]...[]='value' |
array | $data | - the final data array containing all POST parameters : 1 row = 1 parameter |
format_postdata_for_curlcall | ( | $postdata | ) |
Transform a PHP array into POST parameter (see the recursive function format_array_postdata_for_curlcall)
array | $postdata |
string | containing all POST parameters (1 row = 1 POST parameter) |
fulldelete | ( | $location | ) |
Recursively delete the file or folder with path $location.
That is, if it is a file delete it. If it is a folder, delete all its content then delete it. If $location does not exist to start, that is not considered an error.
string | $location | the path to remove. |
bool |
get_mimetype_description | ( | $obj, | |
$capitalise = false ) |
Obtains descriptions for file types (e.g.
'Microsoft Word document') from the mimetypes.php language file.
mixed | $obj | - instance of stored_file or file_info or array/stdClass with field 'filename' and 'mimetype', or just a string with mimetype (though it is recommended to have filename); In case of array/stdClass the field 'mimetype' is optional. |
bool | $capitalise | If true, capitalises first character of result |
string | Text description |
get_mimetype_for_sending | ( | $filename = '' | ) |
Determine a file's MIME type based on the given filename using the function mimeinfo.
This function retrieves a file's MIME type for a file that will be sent to the user. This should only be used for file-sending purposes just like in send_stored_file, send_file, and send_temp_file. Should the file's MIME type cannot be determined by mimeinfo, it will return 'application/octet-stream' as a default MIME type which should tell the browser "I don't know what type of file this is, so just download it.".
string | $filename | The file's filename. |
string | The file's MIME type or 'application/octet-stream' if it cannot be determined. |
& get_mimetypes_array | ( | ) |
Returns a list of information about file types based on extensions.
The following elements expected in value array for each extension: 'type' - mimetype 'icon' - location of the icon file. If value is FILENAME, then either pix/f/FILENAME.gif or pix/f/FILENAME.png must be present in moodle and contain 16x16 filetype icon; also files with bigger sizes under names FILENAME-24, FILENAME-32, FILENAME-64, FILENAME-128, FILENAME-256 are recommended. 'groups' (optional) - array of filetype groups this filetype extension is part of; commonly used in moodle the following groups:
array | List of information about file types based on extensions. Associative array of extension (lower-case) to associative array from 'element name' to data. Current element names are 'type' and 'icon'. Unknown types should use the 'xxx' entry which includes defaults. |
get_moodle_proxy_url | ( | ) |
Returns the moodle proxy configuration as a formatted url.
string | the string to use for proxy settings. |
mimeinfo | ( | $element, | |
$filename ) |
Obtains information about a filetype based on its extension.
Will use a default if no information is present about that particular extension.
string | $element | Desired information (usually 'icon' for icon filename or 'type' for MIME type. Can also be 'icon24', ...32, 48, 64, 72, 80, 96, 128, 256) |
string | $filename | Filename we're looking up |
string | Requested piece of information from array |
mimeinfo_from_type | ( | $element, | |
$mimetype ) |
Obtains information about a filetype based on the MIME type rather than the other way around.
string | $element | Desired information ('extension', 'icon', etc.) |
string | $mimetype | MIME type we're looking up |
string | Requested piece of information from array |
readfile_accel | ( | $file, | |
$mimetype, | |||
$accelerate ) |
Enhanced readfile() with optional acceleration.
string | stored_file | $file | |
string | $mimetype | |
bool | $accelerate |
void |
readfile_allow_large | ( | $path, | |
$filesize = -1 ) |
The readfile function can fail when files are larger than 2GB (even on 64-bit platforms).
This wrapper uses readfile for small files and custom code for large ones.
string | $path | Path to file |
int | $filesize | Size of file (if left out, will get it automatically) |
int|bool | Size read (will always be $filesize) or false if failed |
readstring_accel | ( | $string, | |
$mimetype, | |||
$accelerate = false ) |
Similar to readfile_accel() but designed for strings.
string | $string | |
string | $mimetype | |
bool | $accelerate | Ignored |
void |
send_content_uncached | ( | $content, | |
$filename ) |
Serve content which is not meant to be cached.
This is only intended to be used for volatile public files, for instance when development is enabled, or when caching is not required on a public resource.
string | $content | Raw content. |
string | $filename | The file name. |
void |
send_file | ( | $path, | |
$filename, | |||
$lifetime = null, | |||
$filter = 0, | |||
$pathisstring = false, | |||
$forcedownload = false, | |||
$mimetype = '', | |||
$dontdie = false, | |||
array | $options = array() ) |
Handles the sending of file data to the user's browser, including support for byteranges etc.
string | stored_file | $path | Path of file on disk (including real filename), or actual content of file as string, or stored_file object |
string | $filename | Filename to send |
int | $lifetime | Number of seconds before the file should expire from caches (null means $CFG->filelifetime) |
int | $filter | 0 (default)=no filtering, 1=all files, 2=html files only |
bool | $pathisstring | If true (default false), $path is the content to send and not the pathname. Forced to false when $path is a stored_file object. |
bool | $forcedownload | If true (default false), forces download of file rather than view in browser/plugin |
string | $mimetype | Include to specify the MIME type; leave blank to have it guess the type from $filename |
bool | $dontdie | - return control to caller afterwards. this is not recommended and only used for cleanup tasks. if this is passed as true, ignore_user_abort is called. if you don't want your processing to continue on cancel, you must detect this case when control is returned using connection_aborted. Please not that session is closed and should not be reopened. |
array | $options | An array of options, currently accepts:
|
null | script execution stopped unless $dontdie is true |
stdClass send_file_not_found | ( | ) |
Requested file is not found or not accessible, does not return, terminates script.
$CFG @global stdClass $COURSE
send_stored_file | ( | $storedfile, | |
$lifetime = null, | |||
$filter = 0, | |||
$forcedownload = false, | |||
array | $options = array() ) |
Handles the sending of file data to the user's browser, including support for byteranges etc.
The $options parameter supports the following keys: (string|null) preview - send the preview of the file (e.g. "thumb" for a thumbnail) (string|null) filename - overrides the implicit filename (bool) dontdie - return control to caller afterwards. this is not recommended and only used for cleanup tasks. if this is passed as true, ignore_user_abort is called. if you don't want your processing to continue on cancel, you must detect this case when control is returned using connection_aborted. Please not that session is closed and should not be reopened (string|null) cacheability - force the cacheability setting of the HTTP response, "private" or "public", when $lifetime is greater than 0. Cacheability defaults to "private" when logged in as other than guest; otherwise, defaults to "public". (string|null) immutable - set the immutable cache setting in the HTTP response, when served under HTTPS. Note: it's up to the consumer to set it properly i.e. when serving a "versioned" URL.
stored_file | $storedfile | local file object |
int | $lifetime | Number of seconds before the file should expire from caches (null means $CFG->filelifetime) |
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 |
null | script execution stopped unless $options['dontdie'] is true |
send_temp_file | ( | $path, | |
$filename, | |||
$pathisstring = false ) |
Handles the sending of temporary file to user, download is forced.
File is deleted after abort or successful sending, does not return, script terminated
string | $path | path to file, preferably from moodledata/temp/something; or content of file itself |
string | $filename | proposed file name when saving file |
bool | $pathisstring | If the path is string |
send_temp_file_finished | ( | $path | ) |
Internal callback function used by send_temp_file()
string | $path |