PclZip::properties PHP Method

properties() public method

--------------------------------------------------------------------------------
public properties ( )
    public function properties()
    {
        // ----- Reset the error handler
        $this->privErrorReset();
        // ----- Magic quotes trick
        $this->privDisableMagicQuotes();
        // ----- Check archive
        if (!$this->privCheckFormat()) {
            $this->privSwapBackMagicQuotes();
            return 0;
        }
        // ----- Default properties
        $v_prop = array();
        $v_prop['comment'] = '';
        $v_prop['nb'] = 0;
        $v_prop['status'] = 'not_exist';
        // ----- Look if file exists
        if (@is_file($this->zipname)) {
            // ----- Open the zip file
            if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) {
                $this->privSwapBackMagicQuotes();
                // ----- Error log
                PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \'' . $this->zipname . '\' in binary read mode');
                // ----- Return
                return 0;
            }
            // ----- Read the central directory informations
            $v_central_dir = array();
            if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) {
                $this->privSwapBackMagicQuotes();
                return 0;
            }
            // ----- Close the zip file
            $this->privCloseFd();
            // ----- Set the user attributes
            $v_prop['comment'] = $v_central_dir['comment'];
            $v_prop['nb'] = $v_central_dir['entries'];
            $v_prop['status'] = 'ok';
        }
        // ----- Magic quotes trick
        $this->privSwapBackMagicQuotes();
        // ----- Return
        return $v_prop;
    }

Usage Example

function themedrive_unzip($file, $dir)
{
    if (!current_user_can('edit_files')) {
        echo 'Oops, sorry you are not authorized to do this';
        return false;
    }
    if (!class_exists('PclZip')) {
        require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
    }
    $unzipArchive = new PclZip($file);
    $list = $unzipArchive->properties();
    if (!$list['nb']) {
        return false;
    }
    //echo "Number of files in archive : ".$list['nb']."<br>";
    echo "Copying the files<br>";
    $result = $unzipArchive->extract(PCLZIP_OPT_PATH, $dir);
    if ($result == 0) {
        echo 'Could not unarchive the file: ' . $unzipArchive->errorInfo(true) . ' <br />';
        return false;
    } else {
        //print_r($result);
        foreach ($result as $item) {
            if ($item['status'] != 'ok') {
                echo $item['stored_filename'] . ' ... ' . $item['status'] . '<br>';
            }
        }
        return true;
    }
}
All Usage Examples Of PclZip::properties