opr.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /*
  3. |-----------------------------|
  4. | 77777 ZZZZZ IIIII PPPPP |
  5. | 7 Z I P P |
  6. | 7 - Z I PPPP |
  7. | 7 Z I P |
  8. | 7 ZZZZZ IIIII P |
  9. |-----------------------------|
  10. Yes ! This is an 7Zip logo
  11. */
  12. $rand = $_GET["rand"];
  13. if(!isset($_GET["method"])){
  14. die('["Method Error"]');
  15. }
  16. /*
  17. if(!isset($_GET["rand"])){
  18. die('["Rand Error"]');
  19. }
  20. if(!isset($_GET["file"])){
  21. die('["File Error"]');
  22. }
  23. */
  24. if($_GET["method"] == "ListAORDir"){
  25. $result = [];
  26. $dir = $_GET["dir"] !== "" ? "../".$_GET["dir"]."/" : "../";
  27. $data = scandir($dir,1);
  28. array_pop($data); // this two use for remove .. and .
  29. array_pop($data);
  30. foreach($data as $value){
  31. if(is_dir($dir.$value)){
  32. array_push($result,$value);
  33. }
  34. }
  35. echo json_encode($result);
  36. }else if($_GET["method"] == "l"){
  37. $filesnumber = -1;
  38. $FileInformation = [];
  39. $SevenZHeader = [];
  40. exec('sudo ./7za l "'.$_GET["file"].'" -ba -slt',$output);
  41. if($_GET["dir"] !== ""){
  42. $dir = $_GET["dir"];
  43. }else{
  44. $dir = ".";
  45. }
  46. //* Special designed handler for ZIP (use for show folder)
  47. if(pathinfo($_GET["file"])['extension'] == "zip"){
  48. for($i = 0;$i < sizeOf($output);$i++){
  49. preg_match_all('/(.*[^=]) = (.*)/', $output[$i], $tmp);
  50. if($tmp[1][0] == "Path" && pathinfo($tmp[2][0])["dirname"] !== "."){
  51. if(!in_array("Path = ".pathinfo($tmp[2][0])["dirname"],$output)){
  52. array_push($output,"Path = ".pathinfo($tmp[2][0])["dirname"]);
  53. array_push($output,"Attributes = D");
  54. array_push($output,"");
  55. }
  56. }
  57. }
  58. }
  59. //print_r($output);
  60. for($i = 0;$i < sizeOf($output);$i++){
  61. preg_match_all('/(.*[^=]) = (.*)/', $output[$i], $tmp);
  62. if($tmp[1][0] == "Path"){
  63. $currDir = pathinfo($tmp[2][0])["dirname"];
  64. if($currDir == $dir){
  65. $filesnumber += 1;
  66. }
  67. }
  68. if($tmp[1][0] !== NULL && $currDir == $dir){
  69. $FileInformation[$filesnumber][$tmp[1][0]] = $tmp[2][0];
  70. if(!in_array($tmp[1][0],$SevenZHeader)){
  71. array_push($SevenZHeader,$tmp[1][0]);
  72. }
  73. }
  74. }
  75. echo json_encode(array("Header" => $SevenZHeader,"Information" => $FileInformation));
  76. }else if($_GET["method"] == "e"){
  77. $rand = $_GET["rand"];
  78. mkdir('tmp/'.$rand,0777);
  79. system('./7za e -bsp1 -bso0 "'.$_GET["file"].'" "'.$_GET["dir"].'" -o"tmp/'.$rand.'/" > tmp/'.$rand.'messages',$output);
  80. echo json_encode(array("Extract finished. e"));
  81. }else if($_GET["method"] == "x"){
  82. $rand = $_GET["rand"];
  83. mkdir('tmp/'.$rand,0777);
  84. system('./7za x -bsp1 -bso0 "'.$_GET["file"].'" "'.$_GET["dir"].'" -o"tmp/'.$rand.'/" > tmp/'.$rand.'messages',$output);
  85. echo json_encode(array("Extract finished. x"));
  86. }