aphexx/php-vpk-reader

There is no license information available for the latest version (dev-master) of this package.

Library for reading VPK (Valve Pack File).

dev-master 2016-02-18 16:40 UTC

This package is not auto-updated.

Last update: 2024-09-20 18:23:42 UTC


README

VPK archive reader in PHP

Reading file contents

$vpk_file = 'package_dir.vpk';
$vpk = new VPKReader\VPK($vpk_file);
$data = $vpk->read_file('/path/to/file.txt', 10000);
echo $data;

Getting directory tree

$vpk_file = 'package_dir.vpk';
$vpk = new VPKReader\VPK($vpk_file);
$ent_tree = $vpk->vpk_entries

$print_tree = function($node, $pwd='') use (&$print_tree){
        if(!is_null($node) && count($node) > 0) {
                if(is_array($node)){
                        echo '<ul>';
                        foreach($node as $name=>$subn) {
                                $fp = "$pwd/$name";
                                echo "<li>$fp";
                                $print_tree($subn, $fp);
                                echo '</li>';
                        }
                        echo '</ul>';
                }else{ // Node
                        echo " | size: $node->size bytes";
                }
        }
};
$print_tree($ent_tree);