PageRenderTime 26ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/classes/options/unzip.php

http://rapidleech.googlecode.com/
PHP | 99 lines | 98 code | 1 blank | 0 comment | 16 complexity | f972192491c9741b474db1ce7e6ac396 MD5 | raw file
  1. <?php
  2. function unzip() {
  3. global $list, $PHP_SELF;
  4. ?>
  5. <form method="post" action="<?php echo $PHP_SELF; ?>">
  6. <input type="hidden" name="act" value="unzip_go" />
  7. <table align="center">
  8. <tr>
  9. <td>
  10. <table>
  11. <?php
  12. for($i = 0; $i < count ( $_GET ["files"] ); $i ++) {
  13. $file = $list [$_GET ["files"] [$i]];
  14. require_once (CLASS_DIR . "unzip.php");
  15. if (file_exists($file['name'])) {
  16. $zip = new dUnzip2 ( $file['name'] );
  17. $flist = $zip->getList();
  18. ?>
  19. <tr><td align="center">
  20. <input type="hidden" name="files[]" value="<?php echo $_GET['files'][$i]; ?>" />
  21. <b><?php echo basename($file['name']); ?></b> (<?php echo count($flist).' '.lang(204); ?>)
  22. </td></tr>
  23. <tr><td>
  24. <div style="overflow-y:scroll; height:150px; padding-left:5px;">
  25. <?php
  26. foreach ($flist as $property) {
  27. echo($property['file_name'].'<br />');
  28. }
  29. ?>
  30. </div>
  31. </td></tr>
  32. <?php
  33. }
  34. }
  35. ?>
  36. </table>
  37. </td>
  38. <td><input type="submit" name="submit" value="<?php echo lang(205); ?>" /></td>
  39. </tr>
  40. <tr><td></td></tr>
  41. </table>
  42. </form>
  43. <?php
  44. }
  45. function unzip_go() {
  46. global $list, $options;
  47. require_once (CLASS_DIR . "unzip.php");
  48. $any_file_unzippped = false;
  49. for($i = 0; $i < count ( $_POST ["files"] ); $i ++) {
  50. $file = $list [$_POST ["files"] [$i]];
  51. if (file_exists ( $file ["name"] )) {
  52. $zip = new dUnzip2 ( $file ["name"] );
  53. $allf = $zip->getList ();
  54. $file_inside_zip_exists = false;
  55. $forbidden_inside_zip = false;
  56. foreach ($allf as $k => $properties) {
  57. if (file_exists($options['download_dir'].basename($properties['file_name']))) {
  58. $file_inside_zip_exists = true; break;
  59. }
  60. }
  61. if ($options['check_these_before_unzipping']) {
  62. foreach ( $allf as $k => $property ) {
  63. $zfiletype = strrchr ( $property ['file_name'], "." );
  64. if (is_array ( $options['forbidden_filetypes'] ) && in_array ( strtolower ( $zfiletype ), $options['forbidden_filetypes'] )) {
  65. $forbidden_inside_zip = true; break;
  66. }
  67. }
  68. }
  69. if ($file_inside_zip_exists) {
  70. echo 'Some file(s) inside <b>'.htmlentities(basename($file["name"])).'</b> already exist on download directory';
  71. echo "<br /><br />";
  72. }
  73. elseif ($forbidden_inside_zip) {
  74. printf(lang(181), $zfiletype);
  75. echo "<br /><br />";
  76. }
  77. else {
  78. $zip->unzipAll ( $options['download_dir'] );
  79. if ($zip->getList () != false) {
  80. $any_file_unzippped = true;
  81. echo '<b>'.htmlentities(basename($file["name"])).'</b>&nbsp;unzipped successfully<br /><br />';
  82. foreach ($allf as $k => $properties) {
  83. $efile = realpath($options['download_dir']).'/'.basename($properties['file_name']);
  84. if (is_file($efile)) {
  85. $time = filemtime($efile); while (isset($list[$time])) { $time++; }
  86. $list[$time] = array("name" => $efile, "size" => bytesToKbOrMbOrGb(filesize($efile)), "date" => $time);
  87. }
  88. }
  89. if (!updateListInFile($list)) { echo lang(146)."<br /><br />"; }
  90. }
  91. else {
  92. echo "File <b>".$file["name"]."</b> not found!<br /><br />";
  93. }
  94. }
  95. }
  96. }
  97. }
  98. ?>