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]
Functions for file handling.
Copyright: | 1999 onwards Martin Dougiamas (http://dougiamas.com) |
License: | http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
File Size: | 5289 lines (207 kb) |
Included or required: | 6 times |
Referenced: | 11 times |
Includes or requires: | 0 files |
curl:: (32 methods):
__construct()
resetopt()
get_cacert()
resetcookie()
setopt()
cleanopt()
resetHeader()
setHeader()
getResponse()
get_raw_response()
formatHeader()
apply_opt()
download()
get_security()
set_security()
multi()
reset_request_state_vars()
mock_response()
check_securityhelper_blocklist()
request()
head()
patch()
post()
get()
download_one()
put()
delete()
trace()
options()
get_info()
get_errno()
strip_double_headers()
curl_cache:: (6 methods):
__construct()
get()
set()
cleanup()
refresh()
file_pluginfile()
__construct($settings = array() X-Ref |
Curl constructor. Allowed settings are: proxy: (bool) use proxy server, null means autodetect non-local from url debug: (bool) use debug output cookie: (string) path to cookie file, false if none cache: (bool) use cache module_cache: (string) type of cache securityhelper: (\core\files\curl_security_helper_base) helper object providing URL checking for requests. ignoresecurity: (bool) set true to override and ignore the security helper when making requests. param: array $settings |
resetopt() X-Ref |
Resets the CURL options that have already been set |
get_cacert() X-Ref |
Get the location of ca certificates. return: string absolute file path or empty if default used |
resetcookie() X-Ref |
Reset Cookie |
setopt($options = array() X-Ref |
Set curl options. Do not use the curl constants to define the options, pass a string corresponding to that constant. Ie. to set CURLOPT_MAXREDIRS, pass array('CURLOPT_MAXREDIRS' => 10) or array('maxredirs' => 10) to this method. param: array $options If array is null, this function will reset the options to default value. return: void |
cleanopt() X-Ref |
Reset http method |
resetHeader() X-Ref |
Resets the HTTP Request headers (to prepare for the new request) |
setHeader($header) X-Ref |
Set HTTP Request Header param: array $header |
getResponse() X-Ref |
Get HTTP Response Headers return: array of arrays |
get_raw_response() X-Ref |
Get raw HTTP Response Headers return: array of strings |
formatHeader($ch, $header) X-Ref |
private callback function Formatting HTTP Response Header We only keep the last headers returned. For example during a redirect the redirect headers will not appear in {@link self::getResponse()}, if you need to use those headers, refer to {@link self::get_raw_response()}. param: resource $ch Apparently not used param: string $header return: int The strlen of the header |
apply_opt($curl, $options) X-Ref |
Set options for individual curl instance param: resource $curl A curl handle param: array $options return: resource The curl handle |
download($requests, $options = array() X-Ref |
Download multiple files in parallel Calls {@link multi()} with specific download headers <code> $c = new curl(); $file1 = fopen('a', 'wb'); $file2 = fopen('b', 'wb'); $c->download(array( array('url'=>'http://localhost/', 'file'=>$file1), array('url'=>'http://localhost/20/', 'file'=>$file2) )); fclose($file1); fclose($file2); </code> or <code> $c = new curl(); $c->download(array( array('url'=>'http://localhost/', 'filepath'=>'/tmp/file1.tmp'), array('url'=>'http://localhost/20/', 'filepath'=>'/tmp/file2.tmp') )); </code> param: array $requests An array of files to request { param: array $options An array of options to set return: array An array of results |
get_security() X-Ref |
Returns the current curl security helper. return: \core\files\curl_security_helper instance. |
set_security($securityobject) X-Ref |
Sets the curl security helper. param: \core\files\curl_security_helper $securityobject instance/subclass of the base curl_security_helper class. return: bool true if the security helper could be set, false otherwise. |
multi($requests, $options = array() X-Ref |
Multi HTTP Requests This function could run multi-requests in parallel. param: array $requests An array of files to request param: array $options An array of options to set return: array An array of results |
reset_request_state_vars() X-Ref |
Helper function to reset the request state vars. return: void. |
mock_response($response) X-Ref |
For use only in unit tests - we can pre-set the next curl response. This is useful for unit testing APIs that call external systems. param: string $response |
check_securityhelper_blocklist(string $url) X-Ref |
check_securityhelper_blocklist. Checks whether the given URL is blocked by checking both plugin's security helpers and core curl security helper or any curl security helper that passed to curl class constructor. If ignoresecurity is set to true, skip checking and consider the url is not blocked. This augments all installed plugin's security helpers if there is any. param: string $url the url to check. return: string - an error message if URL is blocked or null if URL is not blocked. |
request($url, $options = array() X-Ref |
Single HTTP Request param: string $url The URL to request param: array $options return: bool |
head($url, $options = array() X-Ref |
HTTP HEAD method param: string $url param: array $options return: bool |
patch($url, $params = '', $options = array() X-Ref |
HTTP PATCH method param: string $url param: array|string $params param: array $options return: bool |
post($url, $params = '', $options = array() X-Ref |
HTTP POST method param: string $url param: array|string $params param: array $options return: bool |
get($url, $params = array() X-Ref |
HTTP GET method param: string $url param: array $params param: array $options return: bool |
download_one($url, $params, $options = array() X-Ref |
Downloads one file and writes it to the specified file handler <code> $c = new curl(); $file = fopen('savepath', 'w'); $result = $c->download_one('http://localhost/', null, array('file' => $file, 'timeout' => 5, 'followlocation' => true, 'maxredirs' => 3)); fclose($file); $download_info = $c->get_info(); if ($result === true) { // file downloaded successfully } else { $error_text = $result; $error_code = $c->get_errno(); } </code> <code> $c = new curl(); $result = $c->download_one('http://localhost/', null, array('filepath' => 'savepath', 'timeout' => 5, 'followlocation' => true, 'maxredirs' => 3)); // ... see above, no need to close handle and remove file if unsuccessful </code> param: string $url param: array|null $params key-value pairs to be added to $url as query string param: array $options request options. Must include either 'file' or 'filepath' return: bool|string true on success or error string on failure |
put($url, $params = array() X-Ref |
HTTP PUT method param: string $url param: array $params param: array $options return: bool |
delete($url, $param = array() X-Ref |
HTTP DELETE method param: string $url param: array $param param: array $options return: bool |
trace($url, $options = array() X-Ref |
HTTP TRACE method param: string $url param: array $options return: bool |
options($url, $options = array() X-Ref |
HTTP OPTIONS method param: string $url param: array $options return: bool |
get_info() X-Ref |
Get curl information return: array |
get_errno() X-Ref |
Get curl error code return: int |
strip_double_headers($input) X-Ref |
When using a proxy, an additional HTTP response code may appear at the start of the header. For example, when using https over a proxy there may be 'HTTP/1.0 200 Connection Established'. Other codes are also possible and some may come with their own headers. If using the return value containing all headers, this function can be called to remove unwanted doubles. Note that it is not possible to distinguish this situation from valid data unless you know the actual response part (below the headers) will not be included in this string, or else will not 'look like' HTTP headers. As a result it is not safe to call this function for general data. param: string $input Input HTTP response return: string HTTP response with additional headers stripped if any |
Class: curl_cache - X-Ref
This class is used by cURL class, use case:__construct($module = 'repository') X-Ref |
Constructor param: string $module which module is using curl_cache |
get($param) X-Ref |
Get cached value param: mixed $param return: bool|string |
set($param, $val) X-Ref |
Set cache value param: mixed $param param: mixed $val |
cleanup($expire) X-Ref |
Remove cache files param: int $expire The number of seconds before expiry |
refresh() X-Ref |
delete current user's cache file |
file_pluginfile($relativepath, $forcedownload, $preview = null, $offline = false, $embed = false) X-Ref |
This function delegates file serving to individual plugins param: string $relativepath param: bool $forcedownload param: null|string $preview the preview mode, defaults to serving the original file param: boolean $offline If offline is requested - don't serve a redirect to an external file, return a file suitable for viewing param: bool $embed Whether this file will be served embed into an iframe. |
file_encode_url($urlbase, $path, $forcedownload=false, $https=false) X-Ref |
Encodes file serving url param: string $urlbase param: string $path /filearea/itemid/dir/dir/file.exe param: bool $forcedownload param: bool $https https url required return: string encoded file url |
file_area_contains_subdirs(context $context, $component, $filearea, $itemid) X-Ref |
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. param: context $context param: string $component param: string $filearea param: string $itemid return: bool |
file_prepare_standard_editor($data, $field, array $options, $context=null, $component=null, $filearea=null, $itemid=null) X-Ref |
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. param: stdClass $data database field that holds the html text with embedded media param: string $field the name of the database field that holds the html text with embedded media param: array $options editor options (like maxifiles, maxbytes etc.) param: stdClass $context context of the editor param: string $component param: string $filearea file area name param: int $itemid item id, required if item exists return: stdClass modified data object |
file_postupdate_standard_editor($data, $field, array $options, $context, $component=null, $filearea=null, $itemid=null) X-Ref |
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. param: stdClass $data raw data submitted by the form param: string $field name of the database field containing the html with embedded media files param: array $options editor options (trusttext, subdirs, maxfiles, maxbytes etc.) param: stdClass $context context, required for existing data param: string $component file component param: string $filearea file area name param: int $itemid item id, required if item exists return: stdClass modified data object |
file_prepare_standard_filemanager($data, $field, array $options, $context=null, $component=null, $filearea=null, $itemid=null) X-Ref |
Saves text and files modified by Editor formslib element param: stdClass $data $database entry field param: string $field name of data field param: array $options various options param: stdClass $context context - must already exist param: string $component param: string $filearea file area name param: int $itemid must already exist, usually means data is in db return: stdClass modified data obejct |
file_postupdate_standard_filemanager($data, $field, array $options, $context, $component, $filearea, $itemid) X-Ref |
Saves files modified by File manager formslib element param: stdClass $data $database entry field param: string $field name of data field param: array $options various options param: stdClass $context context - must already exist param: string $component param: string $filearea file area name param: int $itemid must already exist, usually means data is in db return: stdClass modified data obejct |
file_get_unused_draft_itemid() X-Ref |
Generate a draft itemid return: int a random but available draft itemid that can be used to create a new draft |
file_prepare_draft_area(&$draftitemid, $contextid, $component, $filearea, $itemid, array $options=null, $text=null) X-Ref |
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'); param: int $draftitemid the id of the draft area to use, or 0 to create a new one, in which case this parameter is updated. param: int $contextid This parameter and the next two identify the file area to copy files from. param: string $component param: string $filearea helps indentify the file area. param: int $itemid helps identify the file area. Can be null if there are no files yet. param: array $options text and file options ('subdirs'=>false, 'forcehttps'=>false) param: string $text some html content that needs to have embedded links rewritten to point to the draft area. return: string|null returns string if $text was passed in, the rewritten $text is returned. Otherwise NULL. |
file_rewrite_pluginfile_urls($text, $file, $contextid, $component, $filearea, $itemid, array $options=null) X-Ref |
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. param: string $text The content that may contain ULRs in need of rewriting. param: string $file The script that should be used to serve these files. pluginfile.php, draftfile.php, etc. param: int $contextid This parameter and the next two identify the file area to use. param: string $component param: string $filearea helps identify the file area. param: int $itemid helps identify the file area. param: array $options |
file_get_draft_area_info($draftitemid, $filepath = '/') X-Ref |
Returns information about files in a draft area. param: int $draftitemid the draft area item id. param: string $filepath path to the directory from which the information have to be retrieved. return: array with the following entries: |
file_get_file_area_info($contextid, $component, $filearea, $itemid = 0, $filepath = '/') X-Ref |
Returns information about files in an area. param: int $contextid context id param: string $component component param: string $filearea file area name param: int $itemid item id or all files if not specified param: string $filepath path to the directory from which the information have to be retrieved. return: array with the following entries: |
file_is_draft_area_limit_reached($draftitemid, $areamaxbytes, $newfilesize = 0, $includereferences = false) X-Ref |
Returns whether a draft area has exceeded/will exceed its size limit. Please note that the unlimited value for $areamaxbytes is -1 {@link FILE_AREA_MAX_BYTES_UNLIMITED}, not 0. param: int $draftitemid the draft area item id. param: int $areamaxbytes the maximum size allowed in this draft area. param: int $newfilesize the size that would be added to the current area. param: bool $includereferences true to include the size of the references in the area size. return: bool true if the area will/has exceeded its limit. |
file_is_draft_areas_limit_reached(int $userid) X-Ref |
Returns whether a user has reached their draft area upload rate. param: int $userid The user id return: bool |
file_get_user_used_space() X-Ref |
Get used space of files return: int total bytes |
file_correct_filepath($str) X-Ref |
Convert any string to a valid filepath param: string $str return: string path |
file_get_drafarea_folders($draftitemid, $filepath, &$data) X-Ref |
Generate a folder tree of draft area of current USER recursively param: int $draftitemid param: string $filepath param: mixed $data |
file_get_drafarea_files($draftitemid, $filepath = '/') X-Ref |
Listing all files (including folders) in current path (draft area) used by file manager param: int $draftitemid param: string $filepath return: stdClass |
file_get_all_files_in_draftarea(int $draftitemid, string $filepath = '/') X-Ref |
Returns all of the files in the draftarea. param: int $draftitemid The draft item ID param: string $filepath path for the uploaded files. return: array An array of files associated with this draft item id. |
file_get_submitted_draft_itemid($elname) X-Ref |
Returns draft area itemid for a given element. param: string $elname name of formlib editor element, or a hidden form field that stores the draft area item id, etc. return: int the itemid, or 0 if there is not one yet. |
file_restore_source_field_from_draft_file($storedfile) X-Ref |
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 param: stored_file $storedfile This only works with draft files return: stored_file |
file_remove_editor_orphaned_files($editor) X-Ref |
Removes those files from the user drafts filearea which are not referenced in the editor text. param: stdClass $editor The online text editor element from the submitted form data. |
file_merge_draft_areas($draftitemid, $usercontextid, $text, $forcehttps = false) X-Ref |
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. param: int $draftitemid the id of the primary draft area. param: int $usercontextid the user's context id. param: string $text some html content that needs to have files copied to the correct draft area. param: bool $forcehttps force https urls. return: string $text html content modified with new draft links |
file_replace_file_area_in_text($file, $newid, $text, $forcehttps = false) X-Ref |
Rewrites a file area in arbitrary text. param: array $file General information about the file. param: int $newid The new file area itemid. param: string $text The text to rewrite. param: bool $forcehttps force https urls. return: string The rewritten text. |
file_copy_file_to_file_area($file, $filename, $itemid) X-Ref |
Copies a file from one file area to another. param: array $file Information about the file to be copied. param: string $filename The filename. param: int $itemid The new file area. |
file_save_draft_area_files($draftitemid, $contextid, $component, $filearea, $itemid, array $options=null, $text=null, $forcehttps=false) X-Ref |
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. param: int $draftitemid the id of the draft area to use. Normally obtained param: int $contextid This parameter and the next two identify the file area to save to. param: string $component param: string $filearea indentifies the file area. param: int $itemid helps identifies the file area. param: array $options area options (subdirs=>false, maxfiles=-1, maxbytes=0) param: string $text some html content that needs to have embedded links rewritten param: bool $forcehttps force https urls. return: string|null if $text was passed in, the rewritten $text is returned. Otherwise NULL. |
file_rewrite_urls_to_pluginfile($text, $draftitemid, $forcehttps = false) X-Ref |
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 {@link file_save_draft_area_files()}. param: string $text the content to process. param: int $draftitemid the draft file area the content was using. param: bool $forcehttps whether the content contains https URLs. Default false. return: string the processed content. |
file_set_sortorder($contextid, $component, $filearea, $itemid, $filepath, $filename, $sortorder) X-Ref |
Set file sort order param: int $contextid the context id param: string $component file component param: string $filearea file area. param: int $itemid itemid. param: string $filepath file path. param: string $filename file name. param: int $sortorder the sort order of file. return: bool |
file_reset_sortorder($contextid, $component, $filearea, $itemid=false) X-Ref |
reset file sort order number to 0 param: int $contextid the context id param: string $component param: string $filearea file area. param: int|bool $itemid itemid. return: bool |
file_get_upload_error($errorcode) X-Ref |
Returns description of upload error param: int $errorcode found in $_FILES['filename.ext']['error'] return: string error description string, '' if ok |
format_array_postdata_for_curlcall($arraydata, $currentdata, &$data) X-Ref |
Recursive function formating an array in POST parameter param: array $arraydata - the array that we are going to format and add into &$data array param: string $currentdata - a row of the final postdata array at instant T param: array $data - the final data array containing all POST parameters : 1 row = 1 parameter |
format_postdata_for_curlcall($postdata) X-Ref |
Transform a PHP array into POST parameter (see the recursive function format_array_postdata_for_curlcall) param: array $postdata return: array containing all POST parameters (1 row = 1 POST parameter) |
download_file_content($url, $headers=null, $postdata=null, $fullresponse=false, $timeout=300, $connecttimeout=20, $skipcertverify=false, $tofile=NULL, $calctimeout=false) X-Ref |
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. param: string $url file url starting with http(s):// param: array $headers http headers, null if none. If set, should be an param: array $postdata array means use POST request with given parameters param: bool $fullresponse return headers, responses, etc in a similar way snoopy does param: int $timeout timeout for complete download process including all file transfer param: int $connecttimeout timeout for connection to server; this is the timeout that param: bool $skipcertverify If true, the peer's SSL certificate will not be checked. param: string $tofile store the downloaded content to file instead of returning it. param: bool $calctimeout false by default, true enables an extra head request to try and determine return: stdClass|string|bool stdClass object if $fullresponse is true, false if request failed, true |
get_mimetypes_array() X-Ref |
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: - web_image - image that can be included as <img> in HTML - image - image that we can parse using GD to find it's dimensions, also used for portfolio format - optimised_image - image that will be processed and optimised - video - file that can be imported as video in text editor - audio - file that can be imported as audio in text editor - archive - we can extract files from this archive - spreadsheet - used for portfolio format - document - used for portfolio format - presentation - used for portfolio format 'string' (optional) - the name of the string from lang/en/mimetypes.php that displays human-readable description for this filetype; Function {@link get_mimetype_description()} first looks at the presence of string for particular mimetype (value of 'type'), if not found looks for string specified in 'string' attribute, if not found returns the value of 'type'; 'defaulticon' (boolean, optional) - used by function {@link file_mimetype_icon()} to find an icon for mimetype. If an entry with 'defaulticon' is not found for a particular mimetype, this function will return first found icon; Especially usefull for types such as 'text/plain' return: array List of information about file types based on extensions. |
get_mimetype_for_sending($filename = '') X-Ref |
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.". param: string $filename The file's filename. return: string The file's MIME type or 'application/octet-stream' if it cannot be determined. |
mimeinfo($element, $filename) X-Ref |
Obtains information about a filetype based on its extension. Will use a default if no information is present about that particular extension. param: string $element Desired information (usually 'icon' param: string $filename Filename we're looking up return: string Requested piece of information from array |
mimeinfo_from_type($element, $mimetype) X-Ref |
Obtains information about a filetype based on the MIME type rather than the other way around. param: string $element Desired information ('extension', 'icon', 'icon-24', etc.) param: string $mimetype MIME type we're looking up return: string Requested piece of information from array |
file_file_icon($file, $size = null) X-Ref |
Return the relative icon path for a given file Usage: <code> // $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))); </code> or <code> echo $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file)); </code> param: stored_file|file_info|stdClass|array $file (in case of object attributes $file->filename param: int $size The size of the icon. Defaults to 16 can also be 24, 32, 64, 128, 256 return: string |
file_folder_icon($iconsize = null) X-Ref |
Return the relative icon path for a folder image Usage: <code> $icon = $OUTPUT->image_url(file_folder_icon())->out(); echo html_writer::empty_tag('img', array('src' => $icon)); </code> or <code> echo $OUTPUT->pix_icon(file_folder_icon(32), ''); </code> param: int $iconsize The size of the icon. Defaults to 16 can also be 24, 32, 48, 64, 72, 80, 96, 128, 256 return: string |
file_mimetype_icon($mimetype, $size = NULL) X-Ref |
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. <code> $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))); </code> param: string $mimetype The mimetype to fetch an icon for param: int $size The size of the icon. Defaults to 16 can also be 24, 32, 64, 128, 256 return: string The relative path to the icon |
file_extension_icon($filename, $size = NULL) X-Ref |
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. <code> $filename = '.jpg'; $icon = $OUTPUT->image_url(file_extension_icon($filename))->out(); echo html_writer::empty_tag('img', array('src' => $icon, 'alt' => '...')); </code> param: string $filename The filename to get the icon for param: int $size The size of the icon. Defaults to 16 can also be 24, 32, 64, 128, 256 return: string |
get_mimetype_description($obj, $capitalise=false) X-Ref |
Obtains descriptions for file types (e.g. 'Microsoft Word document') from the mimetypes.php language file. param: mixed $obj - instance of stored_file or file_info or array/stdClass with field param: bool $capitalise If true, capitalises first character of result return: string Text description |
file_get_typegroup($element, $groups) X-Ref |
Returns array of elements of type $element in type group(s) param: string $element name of the element we are interested in, usually 'type' or 'extension' param: string|array $groups one group or array of groups/extensions/mimetypes return: array |
file_extension_in_typegroup($filename, $groups, $checktype = false) X-Ref |
Checks if file with name $filename has one of the extensions in groups $groups param: string $filename name of the file to check param: string|array $groups one group or array of groups to check param: bool $checktype if true and extension check fails, find the mimetype and check if return: bool |
file_mimetype_in_typegroup($mimetype, $groups) X-Ref |
Checks if mimetype $mimetype belongs to one of the groups $groups param: string $mimetype param: string|array $groups one group or array of groups to check return: bool |
send_file_not_found() X-Ref |
Requested file is not found or not accessible, does not return, terminates script |
send_header_404() X-Ref |
Helper function to send correct 404 for server. |
readfile_allow_large($path, $filesize = -1) X-Ref |
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. param: string $path Path to file param: int $filesize Size of file (if left out, will get it automatically) return: int|bool Size read (will always be $filesize) or false if failed |
readfile_accel($file, $mimetype, $accelerate) X-Ref |
Enhanced readfile() with optional acceleration. param: string|stored_file $file param: string $mimetype param: bool $accelerate return: void |
readstring_accel($string, $mimetype, $accelerate = false) X-Ref |
Similar to readfile_accel() but designed for strings. param: string $string param: string $mimetype param: bool $accelerate Ignored return: void |
send_temp_file($path, $filename, $pathisstring=false) X-Ref |
Handles the sending of temporary file to user, download is forced. File is deleted after abort or successful sending, does not return, script terminated param: string $path path to file, preferably from moodledata/temp/something; or content of file itself param: string $filename proposed file name when saving file param: bool $pathisstring If the path is string |
send_temp_file_finished($path) X-Ref |
Internal callback function used by send_temp_file() param: string $path |
send_content_uncached($content, $filename) X-Ref |
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. param: string $content Raw content. param: string $filename The file name. return: void |
file_safe_save_content($content, $destination) X-Ref |
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. param: string $content The file content. param: string $destination The absolute path of the final file. return: void |
send_file($path, $filename, $lifetime = null , $filter=0, $pathisstring=false, $forcedownload=false, $mimetype='',$dontdie=false, array $options = array() X-Ref |
Handles the sending of file data to the user's browser, including support for byteranges etc. param: string|stored_file $path Path of file on disk (including real filename), param: string $filename Filename to send param: int $lifetime Number of seconds before the file should expire from caches (null means $CFG->filelifetime) param: int $filter 0 (default)=no filtering, 1=all files, 2=html files only param: bool $pathisstring If true (default false), $path is the content to send and not the pathname. param: bool $forcedownload If true (default false), forces download of file rather than view in browser/plugin param: string $mimetype Include to specify the MIME type; leave blank to have it guess the type from $filename param: bool $dontdie - return control to caller afterwards. this is not recommended and only used for cleanup tasks. param: array $options An array of options, currently accepts: return: null script execution stopped unless $dontdie is true |
send_stored_file($stored_file, $lifetime=null, $filter=0, $forcedownload=false, array $options=array() X-Ref |
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. param: stored_file $stored_file local file object param: int $lifetime Number of seconds before the file should expire from caches (null means $CFG->filelifetime) param: int $filter 0 (default)=no filtering, 1=all files, 2=html files only param: bool $forcedownload If true (default false), forces download of file rather than view in browser/plugin param: array $options additional options affecting the file serving return: null script execution stopped unless $options['dontdie'] is true |
fulldelete($location) X-Ref |
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. param: string $location the path to remove. return: bool |
byteserving_send_file($handle, $mimetype, $ranges, $filesize) X-Ref |
Send requested byterange of file. param: resource $handle A file handle param: string $mimetype The mimetype for the output param: array $ranges An array of ranges to send param: string $filesize The size of the content if only one range is used |
file_is_executable($filename) X-Ref |
Tells whether the filename is executable. param: string $filename Path to the file. return: bool True if the filename exists and is executable; otherwise, false. |
file_overwrite_existing_draftfile(stored_file $newfile, stored_file $existingfile) X-Ref |
Overwrite an existing file in a draft area. param: stored_file $newfile the new file with the new content and meta-data param: stored_file $existingfile the file that will be overwritten |
file_merge_files_from_draft_area_into_filearea($draftitemid, $contextid, $component, $filearea, $itemid,array $options = null) X-Ref |
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. param: int $draftitemid the id of the draft area to use. param: int $contextid this parameter and the next two identify the file area to save to. param: string $component component name param: string $filearea indentifies the file area param: int $itemid identifies the item id or false for all items in the file area param: array $options area options (subdirs=false, maxfiles=-1, maxbytes=0, areamaxbytes=FILE_AREA_MAX_BYTES_UNLIMITED) |
file_merge_draft_area_into_draft_area($getfromdraftid, $mergeintodraftid) X-Ref |
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. param: int $getfromdraftid the id of the draft area where are the files to merge. param: int $mergeintodraftid the id of the draft area where new files will be merged. |
file_is_svg_image_from_mimetype(string $mimetype) X-Ref |
Attempt to determine whether the specified mime-type is an SVG image or not. param: string $mimetype Mime-type return: bool True if it is an SVG file |
get_moodle_proxy_url() X-Ref |
Returns the moodle proxy configuration as a formatted url return: string the string to use for proxy settings. |