Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
file_packer Class Reference

Abstract class for archiving of files. More...

Inheritance diagram for file_packer:
mbz_packer tgz_packer zip_packer

Public Member Functions

 archive_to_pathname (array $files, $archivefile, $ignoreinvalidfiles=true, file_progress $progress=null)
 Archive files and store the result in os file.
 
 archive_to_storage (array $files, $contextid, $component, $filearea, $itemid, $filepath, $filename, $userid=NULL, $ignoreinvalidfiles=true, file_progress $progress=null)
 Archive files and store the result in file storage.
 
 extract_to_pathname ($archivefile, $pathname, array $onlyfiles=NULL, file_progress $progress=null, $returnbool=false)
 Extract file to given file path (real OS filesystem), existing files are overwritten.
 
 extract_to_storage ($archivefile, $contextid, $component, $filearea, $itemid, $pathbase, $userid=NULL, file_progress $progress=null)
 Extract file to given file path (real OS filesystem), existing files are overwritten.
 
 list_files ($archivefile)
 Returns array of info about all files in archive.
 

Detailed Description

Abstract class for archiving of files.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ archive_to_pathname()

file_packer::archive_to_pathname ( array $files,
$archivefile,
$ignoreinvalidfiles = true,
file_progress $progress = null )
abstract

Archive files and store the result in os file.

The key of the $files array is always the path within the archive, e.g. 'folder/subfolder/file.txt'. There are several options for the values of the array:

  • null = this entry represents a directory, so no file
  • string = full path to file within operating system filesystem
  • stored_file = file within Moodle filesystem
  • array with one string element = use in-memory string for file content

For the string (OS path) and stored_file (Moodle filesystem) cases, you can specify a directory instead of a file to recursively include all files within this directory.

Parameters
array$filesarray with zip paths as keys (archivepath=>ospathname or archivepath=>stored_file)
string$archivefilepath to target zip file
bool$ignoreinvalidfilestrue means ignore missing or invalid files, false means abort on any error
file_progress$progressProgress indicator callback or null if not required
Return values
booltrue if file created, false if not

Reimplemented in mbz_packer, tgz_packer, and zip_packer.

◆ archive_to_storage()

file_packer::archive_to_storage ( array $files,
$contextid,
$component,
$filearea,
$itemid,
$filepath,
$filename,
$userid = NULL,
$ignoreinvalidfiles = true,
file_progress $progress = null )
abstract

Archive files and store the result in file storage.

The key of the $files array is always the path within the archive, e.g. 'folder/subfolder/file.txt'. There are several options for the values of the array:

  • null = this entry represents a directory, so no file
  • string = full path to file within operating system filesystem
  • stored_file = file within Moodle filesystem
  • array with one string element = use in-memory string for file content

For the string (OS path) and stored_file (Moodle filesystem) cases, you can specify a directory instead of a file to recursively include all files within this directory.

Parameters
array$filesArray of files to archive
int$contextidcontext ID
string$componentcomponent
string$fileareafile area
int$itemiditem ID
string$filepathfile path
string$filenamefile name
int$useriduser ID
bool$ignoreinvalidfilestrue means ignore missing or invalid files, false means abort on any error
file_progress$progressProgress indicator callback or null if not required
Return values
stored_file|boolfalse if error stored_file instance if ok

Reimplemented in mbz_packer, tgz_packer, and zip_packer.

◆ extract_to_pathname()

file_packer::extract_to_pathname ( $archivefile,
$pathname,
array $onlyfiles = NULL,
file_progress $progress = null,
$returnbool = false )
abstract

Extract file to given file path (real OS filesystem), existing files are overwritten.

Parameters
stored_file | string$archivefilefull pathname of zip file or stored_file instance
string$pathnametarget directory
array$onlyfilesonly extract files present in the array
file_progress$progressProgress indicator callback or null if not required
bool$returnboolWhether to return a basic true/false indicating error state, or full per-file error details.
Return values
array|boollist of processed files; false if error

Reimplemented in mbz_packer, tgz_packer, and zip_packer.

◆ extract_to_storage()

file_packer::extract_to_storage ( $archivefile,
$contextid,
$component,
$filearea,
$itemid,
$pathbase,
$userid = NULL,
file_progress $progress = null )
abstract

Extract file to given file path (real OS filesystem), existing files are overwritten.

Parameters
string | stored_file$archivefilefull pathname of zip file or stored_file instance
int$contextidcontext ID
string$componentcomponent
string$fileareafile area
int$itemiditem ID
string$pathbasefile path
int$useriduser ID
file_progress$progressProgress indicator callback or null if not required
Return values
array|boollist of processed files; false if error

Reimplemented in mbz_packer, tgz_packer, and zip_packer.

◆ list_files()

file_packer::list_files ( $archivefile)
abstract

Returns array of info about all files in archive.

Parameters
string | file_archive$archivefile
Return values
arrayof file infos

Reimplemented in mbz_packer, tgz_packer, and zip_packer.


The documentation for this class was generated from the following file: