WordPress Unzip Class

Recently while developing the Smarty Pants Client Document Manager I came across an issue with the WordPress unzip function. After some research I found there are few things you have to do to get the unzip function to work properly. The function is mentioned here in the WordPress codex

The function looks simple with its usage example here

<?php 

unzip_file( $file, $to );

 ?>

Should work that easily huh? It doesn’t you need a few extra steps to get the unzip function to work.

Here is the correct way of using this function, you must call the wp_filesystem filter to get this working right. Also remember the folders should be absolute.

<?php
    function _return_direct() { return 'direct'; }
    add_filter('filesystem_method', '_return_direct');
     WP_Filesystem;
    remove_filter('filesystem_method', '_return_direct');
    global $wp_filesystem;
    unzip_file( $_FILES['premium']['tmp_name'],''.ABSPATH.'wp-content/plugins/sp-client-document-manager/' );	

?>

Please post if you have any alternative solutions.

Recent Posts

Leave a Comment