Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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.

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
return: stored_file|bool false if error stored_file instance if ok

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

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
return: bool true if file created, false if not

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

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
return: bool success

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

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
return: bool success

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.

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
return: bool|array list of processed files; false if 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.

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
return: array|bool list of processed files; false if error

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

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