Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/unzip file


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.

$destination wp_upload_dir();
$destination_path $destination['path'];
$unzipfile unzip_file$destination_path.'/filename.zip'$destination_path);
   if ( 
$unzipfile ) {
'Successfully unzipped the file!';       
   } else {
'There was an error unzipping the file.';       


(string) (required) Full path and filename of zip archive
Default: None
(string) (required) Full path on the filesystem to extract archive to
Default: None

Return Values

WP_Error on failure, True on success

Change Log

Since: 2.5

Source File

unzip_file() is located in wp-admin/includes/file.php