Moodle  2.2.1
http://www.collinsharper.com
file_storage Class Reference

Public Member Functions

 __construct ($filedir, $trashdir, $tempdir, $dirpermissions, $filepermissions)
 file_exists ($contextid, $component, $filearea, $itemid, $filepath, $filename)
 file_exists_by_hash ($pathnamehash)
 get_file_instance (stdClass $file_record)
 get_file_by_id ($fileid)
 get_file_by_hash ($pathnamehash)
 get_file ($contextid, $component, $filearea, $itemid, $filepath, $filename)
 is_area_empty ($contextid, $component, $filearea, $itemid=false, $ignoredirs=true)
 get_area_files ($contextid, $component, $filearea, $itemid=false, $sort="sortorder, itemid, filepath, filename", $includedirs=true)
 get_area_tree ($contextid, $component, $filearea, $itemid)
 get_directory_files ($contextid, $component, $filearea, $itemid, $filepath, $recursive=false, $includedirs=true, $sort="filepath, filename")
 delete_area_files ($contextid, $component=false, $filearea=false, $itemid=false)
 delete_area_files_select ($contextid, $component, $filearea, $itemidstest, array $params=null)
 move_area_files_to_new_context ($oldcontextid, $newcontextid, $component, $filearea, $itemid=false)
 create_directory ($contextid, $component, $filearea, $itemid, $filepath, $userid=null)
 create_file_from_storedfile ($file_record, $fileorid)
 create_file_from_url ($file_record, $url, array $options=NULL, $usetempfile=false)
 create_file_from_pathname ($file_record, $pathname)
 create_file_from_string ($file_record, $content)
 convert_image ($file_record, $fid, $newwidth=NULL, $newheight=NULL, $keepaspectratio=true, $quality=NULL)
 add_file_to_pool ($pathname, $contenthash=NULL)
 add_string_to_pool ($content)
 try_content_recovery ($file)
 deleted_file_cleanup ($contenthash)
 cron ()

Static Public Member Functions

static get_pathname_hash ($contextid, $component, $filearea, $itemid, $filepath, $filename)

Protected Member Functions

 path_from_hash ($contenthash)
 trash_path_from_hash ($contenthash)

Detailed Description

File storage class used for low level access to stored files.

Only owner of file area may use this class to access own files, for example only code in mod/assignment/* may access assignment attachments. When some other part of moodle needs to access files of modules it has to use file_browser class instead or there has to be some callback API.

Since:
Moodle 2.0

Definition at line 45 of file file_storage.php.


Constructor & Destructor Documentation

__construct ( filedir,
trashdir,
tempdir,
dirpermissions,
filepermissions 
)

Constructor - do not use directly use

See also:
get_file_storage() call instead.
Parameters:
string$filedirfull path to pool directory
string$trashdirtemporary storage of deleted area
string$tempdirtemporary storage of various files
int$dirpermissionsnew directory permissions
int$filepermissionsnew file permissions

Definition at line 66 of file file_storage.php.

Here is the call graph for this function:


Member Function Documentation

add_file_to_pool ( pathname,
contenthash = NULL 
)

Add file content to sha1 pool.

Parameters:
string$pathnamepath to file
string$contenthashsha1 hash of content if known (performance only)
Returns:
array (contenthash, filesize, newfile)

Definition at line 1104 of file file_storage.php.

Here is the call graph for this function:

Here is the caller graph for this function:

add_string_to_pool ( content)

Add string content to sha1 pool.

Parameters:
string$contentfile content - binary string
Returns:
array (contenthash, filesize, newfile)

Definition at line 1153 of file file_storage.php.

Here is the call graph for this function:

Here is the caller graph for this function:

convert_image ( file_record,
fid,
newwidth = NULL,
newheight = NULL,
keepaspectratio = true,
quality = NULL 
)

Creates new image file from existing.

Parameters:
mixed$file_recordobject or array describing new file
mixedfile id or stored file object
int$newwidthin pixels
int$newheightin pixels
bool$keepaspectratio
int$qualitydepending on image type 0-100 for jpeg, 0-9 (0 means no compression) for png
Returns:
stored_file instance

Definition at line 989 of file file_storage.php.

Here is the call graph for this function:

create_directory ( contextid,
component,
filearea,
itemid,
filepath,
userid = null 
)

Recursively creates directory.

Parameters:
int$contextid
string$component
string$filearea
int$itemid
string$filepath
string$filename
Returns:
bool success

Definition at line 514 of file file_storage.php.

Here is the call graph for this function:

Here is the caller graph for this function:

create_file_from_pathname ( file_record,
pathname 
)

Add new local file.

Parameters:
mixed$file_recordobject or array describing file
string$pathpath to file or content of file
Returns:
stored_file instance

Definition at line 757 of file file_storage.php.

Here is the call graph for this function:

Here is the caller graph for this function:

create_file_from_storedfile ( file_record,
fileorid 
)

Add new local file based on existing local file.

Parameters:
mixed$file_recordobject or array describing changes
mixed$fileoridid or stored_file instance of the existing local file
Returns:
stored_file instance of newly created file

Definition at line 596 of file file_storage.php.

Here is the call graph for this function:

Here is the caller graph for this function:

create_file_from_string ( file_record,
content 
)

Add new local file.

Parameters:
mixed$file_recordobject or array describing file
string$contentcontent of file
Returns:
stored_file instance

Definition at line 871 of file file_storage.php.

Here is the call graph for this function:

Here is the caller graph for this function:

create_file_from_url ( file_record,
url,
array options = NULL,
usetempfile = false 
)

Add new local file.

Parameters:
mixed$file_recordobject or array describing file
string$pathpath to file or content of file
array$options
See also:
download_file_content() options
Parameters:
bool$usetempfileuse temporary file for download, may prevent out of memory problems
Returns:
stored_file instance

Definition at line 704 of file file_storage.php.

Here is the call graph for this function:

cron ( )

Cron cleanup job.

Returns:
void

Definition at line 1291 of file file_storage.php.

Here is the call graph for this function:

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

Delete all area files (optionally limited by itemid).

Parameters:
int$contextid
string$component
string$filearea(all areas in context if not specified)
int$itemid(all files if not specified)
Returns:
bool success

Definition at line 421 of file file_storage.php.

Here is the call graph for this function:

Here is the caller graph for this function:

delete_area_files_select ( contextid,
component,
filearea,
itemidstest,
array params = null 
)

Delete all the files from certain areas where itemid is limited by an arbitrary bit of SQL.

Parameters:
int$contextidthe id of the context the files belong to. Must be given.
string$componentthe owning component. Must be given.
string$fileareathe file area name. Must be given.
string$itemidstestan SQL fragment that the itemid must match. Used in the query like WHERE itemid $itemidstest. Must used named parameters, and may not used named parameters called contextid, component or filearea.
array$paramsany query params used by $itemidstest.

Definition at line 455 of file file_storage.php.

Here is the call graph for this function:

deleted_file_cleanup ( contenthash)

Marks pool file as candidate for deleting.

DO NOT call directly - reserved for core!!

Parameters:
string$contenthash
Returns:
void

Definition at line 1257 of file file_storage.php.

Here is the call graph for this function:

Here is the caller graph for this function:

file_exists ( contextid,
component,
filearea,
itemid,
filepath,
filename 
)

Does this file exist?

Parameters:
int$contextid
string$component
string$filearea
int$itemid
string$filepath
string$filename
Returns:
bool

Definition at line 121 of file file_storage.php.

Here is the call graph for this function:

Here is the caller graph for this function:

file_exists_by_hash ( pathnamehash)

Does this file exist?

Parameters:
string$pathnamehash
Returns:
bool

Definition at line 139 of file file_storage.php.

Here is the caller graph for this function:

get_area_files ( contextid,
component,
filearea,
itemid = false,
sort = "sortorder, itemid, filepath, filename",
includedirs = true 
)

Returns all area files (optionally limited by itemid)

Parameters:
int$contextid
string$component
string$filearea
int$itemid(all files if not specified)
string$sort
bool$includedirs
Returns:
array of stored_files indexed by pathanmehash

Definition at line 257 of file file_storage.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_area_tree ( contextid,
component,
filearea,
itemid 
)

Returns array based tree structure of area files

Parameters:
int$contextid
string$component
string$filearea
int$itemid
Returns:
array each dir represented by dirname, subdirs, files and dirfile array elements

Definition at line 285 of file file_storage.php.

Here is the call graph for this function:

get_directory_files ( contextid,
component,
filearea,
itemid,
filepath,
recursive = false,
includedirs = true,
sort = "filepath, filename" 
)

Returns all files and optionally directories

Parameters:
int$contextid
string$component
string$filearea
int$itemid
int$filepathdirectory path
bool$recursiveinclude all subdirectories
bool$includedirsinclude files and directories
string$sort
Returns:
array of stored_files indexed by pathanmehash

Definition at line 340 of file file_storage.php.

Here is the call graph for this function:

get_file ( contextid,
component,
filearea,
itemid,
filepath,
filename 
)

Fetch locally stored file.

Parameters:
int$contextid
string$component
string$filearea
int$itemid
string$filepath
string$filename
Returns:
stored_file instance if exists, false if not

Definition at line 201 of file file_storage.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_file_by_hash ( pathnamehash)

Fetch file using local file full pathname hash

Parameters:
string$pathnamehash
Returns:
stored_file instance if exists, false if not

Definition at line 180 of file file_storage.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_file_by_id ( fileid)

Fetch file using local file id.

Please do not rely on file ids, it is usually easier to use pathname hashes instead.

Parameters:
int$fileid
Returns:
stored_file instance if exists, false if not

Definition at line 164 of file file_storage.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_file_instance ( stdClass $  file_record)

Create instance of file class from database record.

Parameters:
stdClass$file_recordrecord from the files table
Returns:
stored_file instance of file abstraction class

Definition at line 151 of file file_storage.php.

Here is the caller graph for this function:

static get_pathname_hash ( contextid,
component,
filearea,
itemid,
filepath,
filename 
) [static]

Calculates sha1 hash of unique full path name information.

This hash is a unique file identifier - it is used to improve performance and overcome db index size limits.

Parameters:
int$contextid
string$component
string$filearea
int$itemid
string$filepath
string$filename
Returns:
string sha1 hash

Definition at line 106 of file file_storage.php.

Here is the caller graph for this function:

is_area_empty ( contextid,
component,
filearea,
itemid = false,
ignoredirs = true 
)

Are there any files (or directories)

Parameters:
int$contextid
string$component
string$filearea
bool | int$itemidtem id or false if all items
bool$ignoredirs
Returns:
bool empty

Definition at line 222 of file file_storage.php.

move_area_files_to_new_context ( oldcontextid,
newcontextid,
component,
filearea,
itemid = false 
)

Move all the files in a file area from one context to another.

Parameters:
integer$oldcontextidthe context the files are being moved from.
integer$newcontextidthe context the files are being moved to.
string$componentthe plugin that these files belong to.
string$fileareathe name of the file area.
Returns:
integer the number of files moved, for information.

Definition at line 482 of file file_storage.php.

Here is the call graph for this function:

path_from_hash ( contenthash) [protected]

Return path to file with given hash.

NOTE: must not be public, files in pool must not be modified

Parameters:
string$contenthash
Returns:
string expected file location

Definition at line 1195 of file file_storage.php.

Here is the caller graph for this function:

trash_path_from_hash ( contenthash) [protected]

Return path to file with given hash.

NOTE: must not be public, files in pool must not be modified

Parameters:
string$contenthash
Returns:
string expected file location

Definition at line 1209 of file file_storage.php.

Here is the caller graph for this function:

try_content_recovery ( file)

Tries to recover missing content of file from trash.

Parameters:
object$file_record
Returns:
bool success

Definition at line 1221 of file file_storage.php.

Here is the call graph for this function:


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations