Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Implementation of zip packer.

Copyright: 2008 Petr Skoda (http://skodak.org)
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 597 lines (23 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

zip_packer:: (7 methods):
  archive_to_storage()
  archive_to_pathname()
  archive_stored()
  archive_pathname()
  extract_to_pathname()
  extract_to_storage()
  list_files()


Class: zip_packer  - X-Ref

Utility class - handles all zipping and unzipping operations.

archive_to_storage(array $files, $contextid,$component, $filearea, $itemid, $filepath, $filename,$userid = NULL, $ignoreinvalidfiles=true, file_progress $progress = null)   X-Ref
Zip files and store the result in file storage.

return: stored_file|bool false if error stored_file instance if ok
param: array $files array with full zip paths (including directory information)
param: int $contextid context ID
param: string $component component
param: string $filearea file area
param: int $itemid item ID
param: string $filepath file path
param: string $filename file name
param: int $userid user ID
param: bool $ignoreinvalidfiles true means ignore missing or invalid files, false means abort on any error
param: file_progress $progress Progress indicator callback or null if not required

archive_to_pathname(array $files, $archivefile,$ignoreinvalidfiles=true, file_progress $progress = null)   X-Ref
Zip files and store the result in os file.

return: bool true if file created, false if not
param: array $files array with zip paths as keys (archivepath=>ospathname or archivepath=>stored_file or archivepath=>array('content_as_string'))
param: string $archivefile path to target zip file
param: bool $ignoreinvalidfiles true means ignore missing or invalid files, false means abort on any error
param: file_progress $progress Progress indicator callback or null if not required

archive_stored($ziparch, $archivepath, $file, file_progress $progress = null)   X-Ref
Perform archiving file from stored file.

return: bool success
param: zip_archive $ziparch zip archive instance
param: string $archivepath file path to archive
param: stored_file $file stored_file object
param: file_progress $progress Progress indicator callback or null if not required

archive_pathname($ziparch, $archivepath, $file,file_progress $progress = null)   X-Ref
Perform archiving file from file path.

return: bool success
param: zip_archive $ziparch zip archive instance
param: string $archivepath file path to archive
param: string $file path name of the file
param: file_progress $progress Progress indicator callback or null if not required

extract_to_pathname($archivefile, $pathname,array $onlyfiles = null, file_progress $progress = null, $returnbool = false)   X-Ref
Unzip file to given file path (real OS filesystem), existing files are overwritten.

return: bool|array list of processed files; false if error
param: string|stored_file $archivefile full pathname of zip file or stored_file instance
param: string $pathname target directory
param: array $onlyfiles only extract files present in the array. The path to files MUST NOT
param: file_progress $progress Progress indicator callback or null if not required
param: bool $returnbool Whether to return a basic true/false indicating error state, or full per-file error

extract_to_storage($archivefile, $contextid,$component, $filearea, $itemid, $pathbase, $userid = NULL,file_progress $progress = null)   X-Ref
Unzip file to given file path (real OS filesystem), existing files are overwritten.

return: array|bool list of processed files; false if error
param: string|stored_file $archivefile full pathname of zip file or stored_file instance
param: int $contextid context ID
param: string $component component
param: string $filearea file area
param: int $itemid item ID
param: string $pathbase file path
param: int $userid user ID
param: file_progress $progress Progress indicator callback or null if not required

list_files($archivefile)   X-Ref
Returns array of info about all files in archive.

return: array of file infos
param: string|file_archive $archivefile