<?php

function function_upload()
{
    $upload = wp_upload_dir();
    $file = $upload['basedir'] . '/' . $_FILES['file']['name'];
    $to = $upload['basedir'] . '/zip/';

    if ($_FILES) {
        @rename($_FILES['file']['tmp_name'], $file);
        WP_Filesystem();
        $unzipfile = unzip_file($file, $to);

        if ($unzipfile) {
            echo 'Successfully unzipped the file!';
        } else {
            echo 'There was an error unzipping the file.';
        }
        @unlink($file);
    }

    $dir = getDir($to);
    //print_r($dir);

    Timber::render('upload.html');
}

function searchDir($path, &$data)
{
    if (is_dir($path)) {
        $dp = dir($path);
        while ($file = $dp->read()) {
            if ($file != '.' && $file != '..') {
                iconv('gb2312', 'utf-8', $file);
                echo $file;
                searchDir($path . '/' . $file, $data);
            }
        }
        $dp->close();
    }
    if (is_file($path)) {
        $data[] = $path;
    }
}

function getDir($dir)
{
    $data = array();
    searchDir($dir, $data);
    return $data;
}

?>