Gistrec

Phar to dir [PHP]

May 19th, 2017
366
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. <?php
  2.  
  3. unphar_toSrc("/home/server/HungerGame/PocketMine-MP.phar", $result);
  4. if (!$result['error']) printf("Phar рхив извлечен в ".$result['tmpDir']."\n");
  5.  
  6. function unphar_toSrc($tmpName, &$result, $name = ""){
  7.     $result = [
  8.         "tmpDir" => null,
  9.         "error" => false
  10.     ];
  11.     try{
  12.         $phar = new Phar($tmpName);
  13.         $pharPath = "phar://{$phar->getPath()}/";
  14.         $patch = explode("/", $tmpName); array_pop($patch);
  15.         $patch = implode("/", $patch)."/unphar";
  16.         $result["tmpDir"] = $tmpDir = getTmpDir($patch);
  17.         foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($pharPath)) as $f){
  18.             $subpath = substr($f, strlen($pharPath));
  19.             @mkdir(dirname($realSubpath = $tmpDir . $subpath), 0777, true);
  20.             copy($f, $realSubpath);
  21.         }
  22.     }catch(Exception $e){
  23.         echo "<pre>";
  24.         echo get_class($e) . ": {$e->getMessage()}";
  25.         echo "\r\n\tat {$e->getFile()}:{$e->getLine()}</pre>";
  26.         $result["error"] = true;
  27.     }
  28. }
  29.  
  30. function getTmpDir($patch){
  31.     for($i = 5; file_exists($patch . $i); $i++);
  32.     $patch .= "$i/";
  33.     mkdir($patch);
  34.     return $patch;
  35. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment