Microweber\Utils\Unzip::native_unzip PHP Метод

native_unzip() публичный Метод

--------------------------------------------------------------------
public native_unzip ( $zip_file, $target_dir = null, $preserve_filepath = true )
    public function native_unzip($zip_file, $target_dir = null, $preserve_filepath = true)
    {
        $file_locations = array();
        if (function_exists('zip_open')) {
            $filename = $zip_file;
            $archive = zip_open($filename);
            if (is_resource($archive)) {
                if (function_exists('set_time_limit')) {
                    @set_time_limit(600);
                }
                while ($entry = zip_read($archive)) {
                    $size = zip_entry_filesize($entry);
                    $name = zip_entry_name($entry);
                    $file_name = basename($name);
                    $is_dir_there = $target_dir . $name;
                    $target_file_to_save = normalize_path($target_dir . $name, false);
                    $dnf = dirname($is_dir_there);
                    if (!is_dir($dnf)) {
                        mkdir_recursive($dnf);
                    }
                    if (is_dir($dnf) and !is_dir($target_file_to_save) and strstr($target_file_to_save, '.')) {
                        $dnf = dirname($target_file_to_save);
                        if (!is_dir($dnf)) {
                            mkdir_recursive($dnf);
                        }
                        $unzipped = @fopen($target_file_to_save, 'wb');
                        while ($size > 0) {
                            $chunkSize = $size > 10240 ? 10240 : $size;
                            $size -= $chunkSize;
                            $chunk = zip_entry_read($entry, $chunkSize);
                            if ($chunk !== false) {
                                @fwrite($unzipped, $chunk);
                            }
                        }
                        $file_locations[] = $target_file_to_save;
                        @fclose($unzipped);
                    }
                }
                zip_close($archive);
            }
            return $file_locations;
        }
        return $file_locations;
    }