Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Files | Namespaces | Classes | Functions | Variables
core_files

Files

file  conversion.php
 Classes for converting files between different file formats.
 
file  conversion_cleanup_task.php
 A scheduled task to clear up old conversion records.
 
file  converter.php
 Class for converting files between different file formats using unoconv.
 
file  converter_interface.php
 Class for converting files between different file formats.
 
file  externallib.php
 External files API.
 
file  file_archive.php
 Abstraction of general file archives.
 
file  file_browser.php
 Utility class for browsing of files.
 
file  file_exceptions.php
 File handling related exceptions.
 
file  file_info.php
 Base for all file browsing classes.
 
file  file_info_context_course.php
 Utility class for browsing of course files.
 
file  file_info_context_coursecat.php
 Utility class for browsing of curse category files.
 
file  file_info_context_module.php
 Utility class for browsing of module files.
 
file  file_info_context_system.php
 Utility class for browsing of system files.
 
file  file_info_context_user.php
 Utility class for browsing of user files.
 
file  file_info_stored.php
 Utility class for browsing of stored files.
 
file  file_packer.php
 Abstraction of general file packer.
 
file  file_progress.php
 Simple interface for receiving progress during long-running file operations.
 
file  file_storage.php
 Core file storage class definition.
 
file  file_system.php
 Core file system class definition.
 
file  file_system_filedir.php
 Core file system class definition.
 
file  filelib.php
 Functions for file handling.
 
file  mbz_packer.php
 Implementation of .mbz packer.
 
file  stored_file.php
 Definition of a class stored_file.
 
file  stored_file_exporter.php
 Class for exporting stored_file data.
 
file  tgz_extractor.php
 Implementation of .tar.gz extractor.
 
file  tgz_packer.php
 Implementation of .tar.gz packer.
 
file  virtual_root_file.php
 Class simulating empty directories.
 
file  xsendfilelib.php
 X-Sendfile support.
 
file  zip_archive.php
 Implementation of zip file archive.
 
file  zip_packer.php
 Implementation of zip packer.
 

Namespaces

namespace  core_files
  
 
namespace  core_files\external
  
 
namespace  core_files\privacy
  
 
namespace  core_files\task
  
 

Classes

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\stored_file_exporter
 Class for exporting stored_file data. More...
 
class  core_files\privacy\provider
 Data provider class. More...
 
class  core_files\task\conversion_cleanup_task
 A scheduled task to clear up old conversion records. More...
 
class  core_files_external
 
class  core_form\privacy\provider
 Implements the privacy API for the core_form subsystem. More...
 
class  curl
 
class  curl_cache
 This class is used by cURL class, use case: More...
 
class  file_access_exception
 
class  file_archive
 Each file archive type must extend this class. More...
 
class  file_browser
 
class  file_exception
 
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
 
interface  file_progress
 
class  file_reference_exception
 
class  file_storage
 
class  file_system
 
class  file_system_filedir
 
class  mbz_packer
 
class  stored_file
 
class  stored_file_creation_exception
 
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
 
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
 
class  zip_packer
 

Functions

 byteserving_send_file ($handle, $mimetype, $ranges, $filesize)
 Send requested byterange of file. More...
 
 download_file_content ($url, $headers=null, $postdata=null, $fullresponse=false, $timeout=300, $connecttimeout=20, $skipcertverify=false, $tofile=NULL, $calctimeout=false)
 
 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. More...
 
 file_copy_file_to_file_area ($file, $filename, $itemid)
 Copies a file from one file area to another. More...
 
 file_correct_filepath ($str)
 Convert any string to a valid filepath. More...
 
stdClass file_encode_url ($urlbase, $path, $forcedownload=false, $https=false)
 Encodes file serving url. More...
 
 file_extension_icon ($filename, $size=NULL)
 
 file_extension_in_typegroup ($filename, $groups, $checktype=false)
 Checks if file with name $filename has one of the extensions in groups $groups. More...
 
 file_file_icon ($file, $size=null)
 Return the relative icon path for a given file. More...
 
 file_folder_icon ($iconsize=null)
 Return the relative icon path for a folder image. More...
 
 file_get_all_files_in_draftarea (int $draftitemid, string $filepath='/')
 Returns all of the files in the draftarea. More...
 
 file_get_drafarea_files ($draftitemid, $filepath='/')
 Listing all files (including folders) in current path (draft area) used by file manager. More...
 
 file_get_drafarea_folders ($draftitemid, $filepath, &$data)
 Generate a folder tree of draft area of current USER recursively. More...
 
stdClass file_get_draft_area_info ($draftitemid, $filepath='/')
 Returns information about files in a draft area. More...
 
 file_get_file_area_info ($contextid, $component, $filearea, $itemid=0, $filepath='/')
 Returns information about files in an area. More...
 
 file_get_submitted_draft_itemid ($elname)
 
 file_get_typegroup ($element, $groups)
 Returns array of elements of type $element in type group(s) More...
 
moodle_database file_get_unused_draft_itemid ()
 
 file_get_upload_error ($errorcode)
 Returns description of upload error. More...
 
moodle_database file_get_user_used_space ()
 Get used space of files $DB @global stdClass $USER. More...
 
 file_is_draft_area_limit_reached ($draftitemid, $areamaxbytes, $newfilesize=0, $includereferences=false)
 Returns whether a draft area has exceeded/will exceed its size limit. More...
 
 file_is_draft_areas_limit_reached (int $userid)
 Returns whether a user has reached their draft area upload rate. More...
 
 file_is_executable ($filename)
 Tells whether the filename is executable. More...
 
 file_merge_draft_area_into_draft_area ($getfromdraftid, $mergeintodraftid)
 Merge files from two draftarea areas. More...
 
 file_merge_draft_areas ($draftitemid, $usercontextid, $text, $forcehttps=false)
 
 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. More...
 
 file_mimetype_icon ($mimetype, $size=NULL)
 
 file_mimetype_in_typegroup ($mimetype, $groups)
 Checks if mimetype $mimetype belongs to one of the groups $groups. More...
 
 file_overwrite_existing_draftfile (stored_file $newfile, stored_file $existingfile)
 Overwrite an existing file in a draft area. More...
 
 file_pluginfile ($relativepath, $forcedownload, $preview=null, $offline=false, $embed=false)
 This function delegates file serving to individual plugins. More...
 
 file_postupdate_standard_editor ($data, $field, array $options, $context, $component=null, $filearea=null, $itemid=null)
 
 file_postupdate_standard_filemanager ($data, $field, array $options, $context, $component, $filearea, $itemid)
 
stdClass file_prepare_draft_area (&$draftitemid, $contextid, $component, $filearea, $itemid, array $options=null, $text=null)
 
 file_prepare_standard_editor ($data, $field, array $options, $context=null, $component=null, $filearea=null, $itemid=null)
 
 file_prepare_standard_filemanager ($data, $field, array $options, $context=null, $component=null, $filearea=null, $itemid=null)
 
 file_remove_editor_orphaned_files ($editor)
 Removes those files from the user drafts filearea which are not referenced in the editor text. More...
 
 file_replace_file_area_in_text ($file, $newid, $text, $forcehttps=false)
 Rewrites a file area in arbitrary text. More...
 
moodle_database file_reset_sortorder ($contextid, $component, $filearea, $itemid=false)
 reset file sort order number to 0 $DB More...
 
 file_restore_source_field_from_draft_file ($storedfile)
 Restore the original source field from draft files. More...
 
 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. More...
 
 file_rewrite_urls_to_pluginfile ($text, $draftitemid, $forcehttps=false)
 
 file_safe_save_content ($content, $destination)
 Safely save content to a certain path. More...
 
stdClass file_save_draft_area_files ($draftitemid, $contextid, $component, $filearea, $itemid, array $options=null, $text=null, $forcehttps=false)
 
moodle_database file_set_sortorder ($contextid, $component, $filearea, $itemid, $filepath, $filename, $sortorder)
 Set file sort order. More...
 
 format_array_postdata_for_curlcall ($arraydata, $currentdata, &$data)
 Recursive function formating an array in POST parameter. More...
 
 format_postdata_for_curlcall ($postdata)
 Transform a PHP array into POST parameter (see the recursive function format_array_postdata_for_curlcall) More...
 
 fulldelete ($location)
 Recursively delete the file or folder with path $location. More...
 
 get_mimetype_description ($obj, $capitalise=false)
 Obtains descriptions for file types (e.g. More...
 
 get_mimetype_for_sending ($filename='')
 Determine a file's MIME type based on the given filename using the function mimeinfo. More...
 
get_mimetypes_array ()
 
 mimeinfo ($element, $filename)
 
 mimeinfo_from_type ($element, $mimetype)
 
 readfile_accel ($file, $mimetype, $accelerate)
 Enhanced readfile() with optional acceleration. More...
 
 readfile_allow_large ($path, $filesize=-1)
 The readfile function can fail when files are larger than 2GB (even on 64-bit platforms). More...
 
 readstring_accel ($string, $mimetype, $accelerate=false)
 Similar to readfile_accel() but designed for strings. More...
 
 send_content_uncached ($content, $filename)
 Serve content which is not meant to be cached. More...
 
 send_file ($path, $filename, $lifetime=null, $filter=0, $pathisstring=false, $forcedownload=false, $mimetype='', $dontdie=false, array $options=array())
 
stdClass send_file_not_found ()
 Requested file is not found or not accessible, does not return, terminates script. More...
 
 send_header_404 ()
 Helper function to send correct 404 for server.
 
 send_stored_file ($stored_file, $lifetime=null, $filter=0, $forcedownload=false, array $options=array())
 
 send_temp_file ($path, $filename, $pathisstring=false)
 Handles the sending of temporary file to user, download is forced. More...
 
 send_temp_file_finished ($path)
 Internal callback function used by send_temp_file() More...
 
 xsendfile ($filepath)
 Serve file using X-Sendfile header, this needs special server module or configuration. More...
 

Variables

const BYTESERVING_BOUNDARY 's1k2o3d4a5k6s7'
 BYTESERVING_BOUNDARY - string unique string constant.
 
const DRAFT_AREA_BUCKET_CAPACITY 50
 Capacity of the draft area bucket when using the leaking bucket technique to limit the draft upload rate.
 
const DRAFT_AREA_BUCKET_LEAK 0.2
 Leaking rate of the draft area bucket when using the leaking bucket technique to limit the draft upload rate.
 
const FILE_AREA_MAX_BYTES_UNLIMITED -1
 Unlimited area size constant.
 
const IGNORE_FILE_MERGE -1
 Do not process file merging when working with draft area files.
 

Detailed Description

Function Documentation

◆ byteserving_send_file()

byteserving_send_file (   $handle,
  $mimetype,
  $ranges,
  $filesize 
)

Send requested byterange of file.

Parameters
resource$handleA file handle
string$mimetypeThe mimetype for the output
array$rangesAn array of ranges to send
string$filesizeThe size of the content if only one range is used

◆ file_area_contains_subdirs()

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.

Parameters
context$context
string$component
string$filearea
string$itemid
Return values
bool

◆ file_copy_file_to_file_area()

file_copy_file_to_file_area (   $file,
  $filename,
  $itemid 
)

Copies a file from one file area to another.

Parameters
array$fileInformation about the file to be copied.
string$filenameThe filename.
int$itemidThe new file area.

◆ file_correct_filepath()

file_correct_filepath (   $str)

Convert any string to a valid filepath.

Todo:
review this function
Parameters
string$str
Return values
stringpath

◆ file_encode_url()

stdClass file_encode_url (   $urlbase,
  $path,
  $forcedownload = false,
  $https = false 
)

Encodes file serving url.

Deprecated:
use moodle_url factory methods instead
Todo:
MDL-31071 deprecate this function $CFG
Parameters
string$urlbase
string$path/filearea/itemid/dir/dir/file.exe
bool$forcedownload
bool$httpshttps url required
Return values
stringencoded file url

◆ file_extension_in_typegroup()

file_extension_in_typegroup (   $filename,
  $groups,
  $checktype = false 
)

Checks if file with name $filename has one of the extensions in groups $groups.

See also
get_mimetypes_array()
Parameters
string$filenamename of the file to check
string | array$groupsone group or array of groups to check
bool$checktypeif true and extension check fails, find the mimetype and check if file mimetype is in mimetypes in groups $groups
Return values
bool

◆ file_file_icon()

file_file_icon (   $file,
  $size = 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));

Parameters
stored_file | file_info | stdClass | array$file(in case of object attributes $file->filename and $file->mimetype are expected)
int$sizeThe size of the icon. Defaults to 16 can also be 24, 32, 64, 128, 256
Return values
string

◆ file_folder_icon()

file_folder_icon (   $iconsize = 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(32), '');

Parameters
int$iconsizeThe size of the icon. Defaults to 16 can also be 24, 32, 48, 64, 72, 80, 96, 128, 256
Return values
string

◆ file_get_all_files_in_draftarea()

file_get_all_files_in_draftarea ( int  $draftitemid,
string  $filepath = '/' 
)

Returns all of the files in the draftarea.

Parameters
int$draftitemidThe draft item ID
string$filepathpath for the uploaded files.
Return values
arrayAn array of files associated with this draft item id.

◆ file_get_drafarea_files()

file_get_drafarea_files (   $draftitemid,
  $filepath = '/' 
)

Listing all files (including folders) in current path (draft area) used by file manager.

Parameters
int$draftitemid
string$filepath
Return values
stdClass

◆ file_get_drafarea_folders()

file_get_drafarea_folders (   $draftitemid,
  $filepath,
$data 
)

Generate a folder tree of draft area of current USER recursively.

Todo:
MDL-31073 use normal return value instead, this does not fit the rest of api here (skodak)
Parameters
int$draftitemid
string$filepath
mixed$data

◆ file_get_draft_area_info()

stdClass file_get_draft_area_info (   $draftitemid,
  $filepath = '/' 
)

Returns information about files in a draft area.

$CFG @global stdClass $USER

Parameters
int$draftitemidthe draft area item id.
string$filepathpath to the directory from which the information have to be retrieved.
Return values
arraywith 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()

file_get_file_area_info (   $contextid,
  $component,
  $filearea,
  $itemid = 0,
  $filepath = '/' 
)

Returns information about files in an area.

Parameters
int$contextidcontext id
string$componentcomponent
string$fileareafile area name
int$itemiditem id or all files if not specified
string$filepathpath to the directory from which the information have to be retrieved.
Return values
arraywith 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.
Since
Moodle 3.4

◆ file_get_typegroup()

file_get_typegroup (   $element,
  $groups 
)

Returns array of elements of type $element in type group(s)

Parameters
string$elementname of the element we are interested in, usually 'type' or 'extension'
string | array$groupsone group or array of groups/extensions/mimetypes
Return values
array

◆ file_get_upload_error()

file_get_upload_error (   $errorcode)

Returns description of upload error.

Parameters
int$errorcodefound in $_FILES['filename.ext']['error']
Return values
stringerror description string, '' if ok

◆ file_get_user_used_space()

moodle_database file_get_user_used_space ( )

Get used space of files $DB @global stdClass $USER.

Return values
inttotal bytes

◆ file_is_draft_area_limit_reached()

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.

Parameters
int$draftitemidthe draft area item id.
int$areamaxbytesthe maximum size allowed in this draft area.
int$newfilesizethe size that would be added to the current area.
bool$includereferencestrue to include the size of the references in the area size.
Return values
booltrue if the area will/has exceeded its limit.
Since
Moodle 2.4

◆ file_is_draft_areas_limit_reached()

file_is_draft_areas_limit_reached ( int  $userid)

Returns whether a user has reached their draft area upload rate.

Parameters
int$useridThe user id
Return values
bool

◆ file_is_executable()

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

Parameters
string$filenamePath to the file.
Return values
boolTrue if the filename exists and is executable; otherwise, false.

◆ file_merge_draft_area_into_draft_area()

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.

Parameters
int$getfromdraftidthe id of the draft area where are the files to merge.
int$mergeintodraftidthe id of the draft area where new files will be merged.
Exceptions
coding_exception
Since
Moodle 3.2

◆ file_merge_files_from_draft_area_into_filearea()

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.

Parameters
int$draftitemidthe id of the draft area to use.
int$contextidthis parameter and the next two identify the file area to save to.
string$componentcomponent name
string$fileareaindentifies the file area
int$itemididentifies the item id or false for all items in the file area
array$optionsarea options (subdirs=false, maxfiles=-1, maxbytes=0, areamaxbytes=FILE_AREA_MAX_BYTES_UNLIMITED)
See also
file_save_draft_area_files
Since
Moodle 3.2

◆ file_mimetype_in_typegroup()

file_mimetype_in_typegroup (   $mimetype,
  $groups 
)

Checks if mimetype $mimetype belongs to one of the groups $groups.

See also
get_mimetypes_array()
Parameters
string$mimetype
string | array$groupsone group or array of groups to check
Return values
bool

◆ file_overwrite_existing_draftfile()

file_overwrite_existing_draftfile ( stored_file  $newfile,
stored_file  $existingfile 
)

Overwrite an existing file in a draft area.

Parameters
stored_file$newfilethe new file with the new content and meta-data
stored_file$existingfilethe file that will be overwritten
Exceptions
moodle_exception
Since
Moodle 3.2

◆ file_pluginfile()

file_pluginfile (   $relativepath,
  $forcedownload,
  $preview = null,
  $offline = false,
  $embed = false 
)

This function delegates file serving to individual plugins.

Parameters
string$relativepath
bool$forcedownload
null | string$previewthe preview mode, defaults to serving the original file
boolean$offlineIf offline is requested - don't serve a redirect to an external file, return a file suitable for viewing offline (e.g. mobile app).
bool$embedWhether this file will be served embed into an iframe.
Todo:
MDL-31088 file serving improments

◆ file_remove_editor_orphaned_files()

file_remove_editor_orphaned_files (   $editor)

Removes those files from the user drafts filearea which are not referenced in the editor text.

Parameters
stdClass$editorThe online text editor element from the submitted form data.

◆ file_replace_file_area_in_text()

file_replace_file_area_in_text (   $file,
  $newid,
  $text,
  $forcehttps = false 
)

Rewrites a file area in arbitrary text.

Parameters
array$fileGeneral information about the file.
int$newidThe new file area itemid.
string$textThe text to rewrite.
bool$forcehttpsforce https urls.
Return values
stringThe rewritten text.

◆ file_reset_sortorder()

moodle_database file_reset_sortorder (   $contextid,
  $component,
  $filearea,
  $itemid = false 
)

reset file sort order number to 0 $DB

Parameters
int$contextidthe context id
string$component
string$fileareafile area.
int | bool$itemiditemid.
Return values
bool

◆ file_restore_source_field_from_draft_file()

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

Parameters
stored_file$storedfileThis only works with draft files
Return values
stored_file

◆ file_rewrite_pluginfile_urls()

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.

Parameters
string$textThe content that may contain ULRs in need of rewriting.
string$fileThe script that should be used to serve these files. pluginfile.php, draftfile.php, etc.
int$contextidThis parameter and the next two identify the file area to use.
string$component
string$fileareahelps identify the file area.
int$itemidhelps identify the file area.
array$optionsbool $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_safe_save_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.

Parameters
string$contentThe file content.
string$destinationThe absolute path of the final file.
Return values
void

◆ file_set_sortorder()

moodle_database file_set_sortorder (   $contextid,
  $component,
  $filearea,
  $itemid,
  $filepath,
  $filename,
  $sortorder 
)

Set file sort order.

$DB

Parameters
int$contextidthe context id
string$componentfile component
string$fileareafile area.
int$itemiditemid.
string$filepathfile path.
string$filenamefile name.
int$sortorderthe sort order of file.
Return values
bool

◆ format_array_postdata_for_curlcall()

format_array_postdata_for_curlcall (   $arraydata,
  $currentdata,
$data 
)

Recursive function formating an array in POST parameter.

Parameters
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()

format_postdata_for_curlcall (   $postdata)

Transform a PHP array into POST parameter (see the recursive function format_array_postdata_for_curlcall)

Parameters
array$postdata
Return values
arraycontaining all POST parameters (1 row = 1 POST parameter)

◆ fulldelete()

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.

Parameters
string$locationthe path to remove.
Return values
bool

◆ get_mimetype_description()

get_mimetype_description (   $obj,
  $capitalise = false 
)

Obtains descriptions for file types (e.g.

'Microsoft Word document') from the mimetypes.php language file.

Parameters
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$capitaliseIf true, capitalises first character of result
Return values
stringText description

◆ get_mimetype_for_sending()

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.".

Parameters
string$filenameThe file's filename.
Return values
stringThe file's MIME type or 'application/octet-stream' if it cannot be determined.

◆ readfile_accel()

readfile_accel (   $file,
  $mimetype,
  $accelerate 
)

Enhanced readfile() with optional acceleration.

Parameters
string | stored_file$file
string$mimetype
bool$accelerate
Return values
void

◆ readfile_allow_large()

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.

Parameters
string$pathPath to file
int$filesizeSize of file (if left out, will get it automatically)
Return values
int|boolSize read (will always be $filesize) or false if failed

◆ readstring_accel()

readstring_accel (   $string,
  $mimetype,
  $accelerate = false 
)

Similar to readfile_accel() but designed for strings.

Parameters
string$string
string$mimetype
bool$accelerateIgnored
Return values
void

◆ send_content_uncached()

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.

Parameters
string$contentRaw content.
string$filenameThe file name.
Return values
void

◆ send_file_not_found()

stdClass send_file_not_found ( )

Requested file is not found or not accessible, does not return, terminates script.

$CFG @global stdClass $COURSE

◆ send_temp_file()

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

Parameters
string$pathpath to file, preferably from moodledata/temp/something; or content of file itself
string$filenameproposed file name when saving file
bool$pathisstringIf the path is string

◆ send_temp_file_finished()

send_temp_file_finished (   $path)

Internal callback function used by send_temp_file()

Parameters
string$path

◆ xsendfile()

xsendfile (   $filepath)

Serve file using X-Sendfile header, this needs special server module or configuration.

Please make sure that all headers are already sent and the all access control checks passed.

Parameters
string$filepath
Return values
boolsuccess