Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- unphar_toSrc("/home/server/HungerGame/PocketMine-MP.phar", $result);
- if (!$result['error']) printf("Phar рхив извлечен в ".$result['tmpDir']."\n");
- function unphar_toSrc($tmpName, &$result, $name = ""){
- $result = [
- "tmpDir" => null,
- "error" => false
- ];
- try{
- $phar = new Phar($tmpName);
- $pharPath = "phar://{$phar->getPath()}/";
- $patch = explode("/", $tmpName); array_pop($patch);
- $patch = implode("/", $patch)."/unphar";
- $result["tmpDir"] = $tmpDir = getTmpDir($patch);
- foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($pharPath)) as $f){
- $subpath = substr($f, strlen($pharPath));
- @mkdir(dirname($realSubpath = $tmpDir . $subpath), 0777, true);
- copy($f, $realSubpath);
- }
- }catch(Exception $e){
- echo "<pre>";
- echo get_class($e) . ": {$e->getMessage()}";
- echo "\r\n\tat {$e->getFile()}:{$e->getLine()}</pre>";
- $result["error"] = true;
- }
- }
- function getTmpDir($patch){
- for($i = 5; file_exists($patch . $i); $i++);
- $patch .= "$i/";
- mkdir($patch);
- return $patch;
- }
Advertisement