Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/filelib.php File Reference

Go to the source code of this file.

Data Structures

class  curl
class  curl_cache
class  filetype_parser

Namespaces

namespace  core

Enumerations

enum  BYTESERVING_BOUNDARY

Functions

 file_encode_url ($urlbase, $path, $forcedownload=false, $https=false)
 file_prepare_standard_editor ($data, $field, array $options, $context=null, $component=null, $filearea=null, $itemid=null)
 file_postupdate_standard_editor ($data, $field, array $options, $context, $component=null, $filearea=null, $itemid=null)
 file_prepare_standard_filemanager ($data, $field, array $options, $context=null, $component=null, $filearea=null, $itemid=null)
 file_postupdate_standard_filemanager ($data, $field, array $options, $context, $component, $filearea, $itemid)
 file_get_unused_draft_itemid ()
 file_prepare_draft_area (&$draftitemid, $contextid, $component, $filearea, $itemid, array $options=null, $text=null)
 file_rewrite_pluginfile_urls ($text, $file, $contextid, $component, $filearea, $itemid, array $options=null)
 file_get_draft_area_info ($draftitemid)
 file_get_user_used_space ()
 file_correct_filepath ($str)
 file_get_drafarea_folders ($draftitemid, $filepath, &$data)
 file_get_drafarea_files ($draftitemid, $filepath= '/')
 file_get_submitted_draft_itemid ($elname)
 file_save_draft_area_files ($draftitemid, $contextid, $component, $filearea, $itemid, array $options=null, $text=null, $forcehttps=false)
 file_rewrite_urls_to_pluginfile ($text, $draftitemid, $forcehttps=false)
 file_set_sortorder ($contextid, $component, $filearea, $itemid, $filepath, $filename, $sortorder)
 file_reset_sortorder ($contextid, $component, $filearea, $itemid=false)
 file_get_upload_error ($errorcode)
 format_array_postdata_for_curlcall ($arraydata, $currentdata, &$data)
 format_postdata_for_curlcall ($postdata)
 download_file_content ($url, $headers=null, $postdata=null, $fullresponse=false, $timeout=300, $connecttimeout=20, $skipcertverify=false, $tofile=NULL, $calctimeout=false)
 download_file_content_header_handler ($received, $ch, $header)
 download_file_content_write_handler ($received, $ch, $data)
 get_mimetypes_array ()
 mimeinfo ($element, $filename)
 mimeinfo_from_type ($element, $mimetype)
 mimeinfo_from_icon ($element, $icon, $all=false)
 file_mimetype_icon ($mimetype, $size=NULL)
 file_extension_icon ($filename, $size=NULL)
 get_mimetype_description ($mimetype, $capitalise=false)
 send_file_not_found ()
 send_temp_file ($path, $filename, $pathisstring=false)
 send_temp_file_finished ($path)
 send_file ($path, $filename, $lifetime= 'default', $filter=0, $pathisstring=false, $forcedownload=false, $mimetype='', $dontdie=false)
 send_stored_file ($stored_file, $lifetime=86400, $filter=0, $forcedownload=false, $filename=null, $dontdie=false)
 get_records_csv ($file, $table)
 put_records_csv ($file, $records, $table=NULL)
 fulldelete ($location)
 byteserving_send_file ($handle, $mimetype, $ranges, $filesize)
 file_modify_html_header ($text)
 file_pluginfile ($relativepath, $forcedownload)

Enumeration Type Documentation

Definition at line 30 of file filelib.php.


Function Documentation

byteserving_send_file ( handle,
mimetype,
ranges,
filesize 
)

Send requested byterange of file.

Parameters:
object$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

Definition at line 2279 of file filelib.php.

Here is the caller graph for this function:

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.

Parameters:
string$urlfile url starting with http(s)://
array$headershttp headers, null if none. If set, should be an associative array of header name => value pairs.
array$postdataarray means use POST request with given parameters
bool$fullresponsereturn headers, responses, etc in a similar way snoopy does (if false, just returns content)
int$timeouttimeout for complete download process including all file transfer (default 5 minutes)
int$connecttimeouttimeout 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$skipcertverifyIf true, the peer's SSL certificate will not be checked. Only use this when already in a trusted location.
string$tofilestore the downloaded content to file instead of returning it.
bool$calctimeoutfalse by default, true enables an extra head request to try and determine filesize and appropriately larger timeout based on $CFG->curltimeoutkbitrate
Returns:
mixed false if request failed or content of the file as string if ok. True if file downloaded into $tofile successfully.

Definition at line 951 of file filelib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

download_file_content_header_handler ( received,
ch,
header 
)

internal implementation

Definition at line 1164 of file filelib.php.

download_file_content_write_handler ( received,
ch,
data 
)

internal implementation

Definition at line 1172 of file filelib.php.

Convert any string to a valid filepath

Parameters:
string$str
Returns:
string path

Definition at line 479 of file filelib.php.

Here is the caller graph for this function:

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

Encodes file serving url

Deprecated:
use moodle_url factory methods instead

object

Parameters:
string$urlbase
string$path/filearea/itemid/dir/dir/file.exe
bool$forcedownload
bool$httpshttps url required
Returns:
string encoded file url

Definition at line 49 of file filelib.php.

Here is the caller graph for this function:

file_extension_icon ( filename,
size = NULL 
)

Returns the relative icon path for a given file name

This function should be used in conjunction with $OUTPUT->pix_url to produce a return the full path to an icon.

$filename = 'jpg'; $icon = $OUTPUT->pix_url(file_extension_icon($filename)); echo '

blah

';

Todo:

When an $OUTPUT->icon method is available this function should be altered to conform with that.

Implement $size

Parameters:
stringfilename The filename to get the icon for
int$sizeThe size of the icon. Defaults to null can also be 32
Returns:
string

Definition at line 1528 of file filelib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

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
Returns:
mixed

Definition at line 525 of file filelib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

file_get_drafarea_folders ( draftitemid,
filepath,
&$  data 
)

Generate a folder tree of draft area of current USER recursively

Parameters:
int$itemid
string$filepath
mixed$data//TODO: use normal return value instead, this does not fit the rest of api here (skodak)

Definition at line 493 of file filelib.php.

Here is the call graph for this function:

file_get_draft_area_info ( draftitemid)

Returns information about files in a draft area.

object object

Parameters:
integer$draftitemidthe draft area item id.
Returns:
array with the following entries: 'filecount' => number of files in the draft area. (more information will be added as needed).

Definition at line 437 of file filelib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Returns draft area itemid for a given element.

Parameters:
string$elnamename of formlib editor element, or a hidden form field that stores the draft area item id, etc.
Returns:
integer the itemid, or 0 if there is not one yet.

Definition at line 593 of file filelib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

object object

Returns:
int a random but available draft itemid that can be used to create a new draft file area.

Definition at line 305 of file filelib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

file_get_upload_error ( errorcode)

Returns description of upload error

Parameters:
int$errorcodefound in $_FILES['filename.ext']['error']
Returns:
string error description string, '' if ok

Definition at line 843 of file filelib.php.

Get used space of files

Returns:
int total bytes

Definition at line 460 of file filelib.php.

Here is the call graph for this function:

file_mimetype_icon ( mimetype,
size = NULL 
)

Returns the relative icon path for a given mime type

This function should be used in conjunction with $OUTPUT->pix_url to produce a return the full path to an icon.

$mimetype = 'image/jpg'; $icon = $OUTPUT->pix_url(file_mimetype_icon($mimetype)); echo '

'.$mimetype.'

';

Todo:
When an $OUTPUT->icon method is available this function should be altered to conform with that.
Parameters:
string$mimetypeThe mimetype to fetch an icon for
int$sizeThe size of the icon. Not yet implemented
Returns:
string The relative path to the icon

Definition at line 1496 of file filelib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

add includes (js and css) into uploaded files before returning them, useful for themes and utf.js includes

object

Parameters:
string$texttext to search and replace
Returns:
string text with added head includes

Definition at line 2348 of file filelib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

file_pluginfile ( relativepath,
forcedownload 
)

Definition at line 3155 of file filelib.php.

Here is the call graph for this function:

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.

Parameters:
object$dataraw data submitted by the form
string$fieldname of the database field containing the html with embedded media files
array$optionseditor options (trusttext, subdirs, maxfiles, maxbytes etc.)
object$contextcontext, required for existing data
stringcomponent
string$fileareafile area name
int$itemiditem id, required if item exists
Returns:
object modified data object

Definition at line 190 of file filelib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

file_postupdate_standard_filemanager ( data,
field,
array options,
context,
component,
filearea,
itemid 
)

Saves files modified by File manager formslib element

Parameters:
object$data$database entry field
string$fieldname of data field
array$optionsvarious options
object$contextcontext - must already exist
string$component
string$fileareafile area name
int$itemidmust already exist, usually means data is in db
Returns:
object modified data obejct

Definition at line 269 of file filelib.php.

Here is the caller graph for this function:

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');

object object

Parameters:
int&$draftitemidthe id of the draft area to use, or 0 to create a new one, in which case this parameter is updated.
integer$contextidThis parameter and the next two identify the file area to copy files from.
string$component
string$fileareahelps indentify the file area.
integer$itemidhelps identify the file area. Can be null if there are no files yet.
array$optionstext and file options ('subdirs'=>false, 'forcehttps'=>false)
string$textsome html content that needs to have embedded links rewritten to point to the draft area.
Returns:
string if $text was passed in, the rewritten $text is returned. Otherwise NULL.

Definition at line 340 of file filelib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters:
object$datadatabase field that holds the html text with embedded media
string$fieldthe name of the database field that holds the html text with embedded media
array$optionseditor options (like maxifiles, maxbytes etc.)
object$contextcontext of the editor
string$component
string$fileareafile area name
int$itemiditem id, required if item exists
Returns:
object modified data object

Definition at line 96 of file filelib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Parameters:
object$data$database entry field
string$fieldname of data field
array$optionsvarious options
object$contextcontext - must already exist
string$component
string$fileareafile area name
int$itemidmust already exist, usually means data is in db
Returns:
object modified data obejct

Definition at line 238 of file filelib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

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

reset file sort order number to 0 object $DB

Parameters:
integer$contextidthe context id
string$component
string$fileareafile area.
integer$itemiditemid.
Returns:
boolean

Definition at line 821 of file filelib.php.

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.

object

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.
integer$contextidThis parameter and the next two identify the file area to use.
string$component
string$fileareahelps identify the file area.
integer$itemidhelps identify the file area.
array$optionstext and file options ('forcehttps'=>false)
Returns:
string the processed text.

Definition at line 402 of file filelib.php.

Here is the caller graph for this function:

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

Parameters:
string$textthe content to process.
int$draftitemidthe draft file area the content was using.
bool$forcehttpswhether the content contains https URLs. Default false.
Returns:
string the processed content.

Definition at line 760 of file filelib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

object object

Parameters:
integer$draftitemidthe id of the draft area to use. Normally obtained from file_get_submitted_draft_itemid('elementname') or similar.
integer$contextidThis parameter and the next two identify the file area to save to.
string$component
string$fileareaindentifies the file area.
integer$itemidhelps identifies the file area.
array$optionsarea options (subdirs=>false, maxfiles=-1, maxbytes=0)
string$textsome html content that needs to have embedded links rewritten to the @PLUGINFILE@ form for saving in the database.
boolean$forcehttpsforce https urls.
Returns:
string if $text was passed in, the rewritten $text is returned. Otherwise NULL.

Definition at line 636 of file filelib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Set file sort order object $DB

Parameters:
integer$contextidthe context id
string$component
string$fileareafile area.
integer$itemiditemid.
string$filepathfile path.
string$filenamefile name.
integer$sortorerthe sort order of file.
Returns:
boolean

Definition at line 800 of file filelib.php.

Here is the caller graph for this function:

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

Definition at line 894 of file filelib.php.

Here is the caller graph for this function:

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

Parameters:
array$postdata
Returns:
array containing all POST parameters (1 row = 1 POST parameter)

Definition at line 912 of file filelib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

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.
Returns:
bool

Definition at line 2237 of file filelib.php.

Here is the caller graph for this function:

get_mimetype_description ( mimetype,
capitalise = false 
)

Obtains descriptions for file types (e.g. 'Microsoft Word document') from the mimetypes.php language file.

Parameters:
string$mimetypeMIME type (can be obtained using the mimeinfo function)
bool$capitaliseIf true, capitalises first character of result
Returns:
string Text description

Definition at line 1548 of file filelib.php.

Here is the call graph for this function:

Returns:
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.

Definition at line 1193 of file filelib.php.

Here is the caller graph for this function:

get_records_csv ( file,
table 
)

Retrieves an array of records from a CSV file and places them into a given table structure

object object

Parameters:
string$fileThe path to a CSV file
string$tableThe table to retrieve columns from
Returns:
bool|array Returns an array of CSV records or false

Definition at line 2119 of file filelib.php.

Here is the call graph for this function:

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.

Parameters:
string$elementDesired information (usually 'icon' for icon filename or 'type' for MIME type)
string$filenameFilename we're looking up
Returns:
string Requested piece of information from array

Definition at line 1380 of file filelib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

mimeinfo_from_icon ( element,
icon,
all = false 
)

Get information about a filetype based on the icon file.

Parameters:
string$elementDesired information (usually 'icon')
string$iconIcon file name without extension
boolean$allreturn all matching entries (defaults to false - best (by ext)/last match)
Returns:
string Requested piece of information from array

Definition at line 1442 of file filelib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

mimeinfo_from_type ( element,
mimetype 
)

Obtains information about a filetype based on the MIME type rather than the other way around.

Parameters:
string$elementDesired information (usually 'icon')
string$mimetypeMIME type we're looking up
Returns:
string Requested piece of information from array

Definition at line 1420 of file filelib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

put_records_csv ( file,
records,
table = NULL 
)

object object

Parameters:
string$fileThe file to put the CSV content into
array$recordsAn array of records to write to a CSV file
string$tableThe table to get columns from
Returns:
bool success

Definition at line 2168 of file filelib.php.

Here is the call graph for this function:

send_file ( path,
filename,
lifetime = 'default',
filter = 0,
pathisstring = false,
forcedownload = false,
mimetype = '',
dontdie = false 
)

Handles the sending of file data to the user's browser, including support for byteranges etc.

object object object

Parameters:
string$pathPath of file on disk (including real filename), or actual content of file as string
string$filenameFilename to send
int$lifetimeNumber of seconds before the file should expire from caches (default 24 hours)
int$filter0 (default)=no filtering, 1=all files, 2=html files only
bool$pathisstringIf true (default false), $path is the content to send and not the pathname
bool$forcedownloadIf true (default false), forces download of file rather than view in browser/plugin
string$mimetypeInclude 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.
Returns:
no return or void, script execution stopped unless $dontdie is true

Do not byteserve (disabled, strings, text and html files).

Definition at line 1694 of file filelib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Requested file is not found or not accessible

Returns:
does not return, terminates script

Definition at line 1565 of file filelib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

send_stored_file ( stored_file,
lifetime = 86400,
filter = 0,
forcedownload = false,
filename = null,
dontdie = false 
)

Handles the sending of file data to the user's browser, including support for byteranges etc.

object object object

Parameters:
object$stored_filelocal file object
int$lifetimeNumber of seconds before the file should expire from caches (default 24 hours)
int$filter0 (default)=no filtering, 1=all files, 2=html files only
bool$forcedownloadIf true (default false), forces download of file rather than view in browser/plugin
string$filenameOverride 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.
Returns:
void no return or void, script execution stopped unless $dontdie is true

Do not byteserve (disabled, strings, text and html files).

Definition at line 1924 of file filelib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters:
string$pathpath to file, preferably from moodledata/temp/something; or content of file itself
string$filenameproposed file name when saving file
bool$pathis content of file
Returns:
does not return, script terminated

Definition at line 1616 of file filelib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Internal callback function used by send_temp_file()

Definition at line 1668 of file filelib.php.

 All Data Structures Namespaces Files Functions Variables Enumerations