Unzips a specified ZIP file to a location on the Filesystem via the WordPress Filesystem Abstraction. Assumes that WP_Filesystem() has already been called and set up. Does not extract a root-level __MACOSX directory, if present.
Attempts to increase the PHP Memory limit to 256M before uncompressing. However, the most memory required shouldn't be much larger than the Archive itself.
<?php unzip_file( $file, $to ); ?>
Basic example showing how to unzip the contents of a .zip file, that resides in the WordPress upload directory, to the same destination.
<?php
WP_Filesystem();
$destination = wp_upload_dir();
$destination_path = $destination['path'];
$unzipfile = unzip_file( $destination_path.'/filename.zip', $destination_path);
if ( is_wp_error( $unzipfile ) ) {
echo 'There was an error unzipping the file.';
} else {
echo 'Successfully unzipped the file!';
}
?>
Since: 2.5
unzip_file() is located in wp-admin/includes/file.php