Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $content = cmd('tar tf %s', [$argv[1]]);
- $tree = [];
- foreach ($content as $fn) {
- if (strpos($fn, '/')) {
- list($d, $f) = explode('/', $fn, 2);
- } else {
- $f = '';
- $d = $fn;
- }
- if ($f) {
- $tree[$d][] = $f;
- } else {
- $tree[$d] = [];
- }
- }
- foreach ($tree as $d => $c) {
- $e = cmd('tar xf %s -O %s', [$argv[1], "{$d}/pathname"]);
- echo $e[0], PHP_EOL;
- if (in_array('asset', $c)) {
- $pi = pathinfo($e[0]);
- @mkdir($pi['dirname'], 0755, true);
- cmd('tar xf %s -O %s > %s', [$argv[1], "{$d}/asset", $e[0]]);
- } else {
- @mkdir($e[0], 0755, true);
- }
- }
- function cmd($c, $args)
- {
- $encoded_args = array_map(
- function ($a) {
- return escapeshellarg($a);
- },
- $args
- );
- exec(vsprintf($c, $encoded_args), $output);
- return $output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement