This page redirects to an external site: https://developer.wordpress.org/reference/functions/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.
<code style="color: #000000"><span style="color: #0000BB"><?php unzip_file</span><span style="color: #007700">( </span><span style="color: #0000BB">$file</span><span style="color: #007700">, </span><span style="color: #0000BB">$to </span><span style="color: #007700">); </span><span style="color: #0000BB">?></span></code>
Basic example showing how to unzip the contents of a .zip file, that resides in the WordPress upload directory, to the same destination.
<code style="color: #000000"><span style="color: #0000BB"><?php
WP_Filesystem</span><span style="color: #007700">();
</span><span style="color: #0000BB">$destination </span><span style="color: #007700">= </span><span style="color: #0000BB">wp_upload_dir</span><span style="color: #007700">();
</span><span style="color: #0000BB">$destination_path </span><span style="color: #007700">= </span><span style="color: #0000BB">$destination</span><span style="color: #007700">[</span><span style="color: #DD0000">'path'</span><span style="color: #007700">];
</span><span style="color: #0000BB">$unzipfile </span><span style="color: #007700">= </span><span style="color: #0000BB">unzip_file</span><span style="color: #007700">( </span><span style="color: #0000BB">$destination_path</span><span style="color: #007700">.</span><span style="color: #DD0000">'/filename.zip'</span><span style="color: #007700">, </span><span style="color: #0000BB">$destination_path</span><span style="color: #007700">);
if ( </span><span style="color: #0000BB">is_wp_error</span><span style="color: #007700">( </span><span style="color: #0000BB">$unzipfile </span><span style="color: #007700">) ) {
echo </span><span style="color: #DD0000">'There was an error unzipping the file.'</span><span style="color: #007700">;
} else {
echo </span><span style="color: #DD0000">'Successfully unzipped the file!'</span><span style="color: #007700">;
}
</span><span style="color: #0000BB">?></span></code>
Since: 2.5
unzip_file() is located in wp-admin/includes/file.php