Просмотр файла download/include/open_zip.php

Размер файла: 8.06Kb
  1. <?php
  2.  
  3.  
  4. $dir_clean = opendir('time_files/open_zip');
  5. while ($file = readdir($dir_clean)) {
  6. if ($file != 'index.php' && $file != '.htaccess' && $file != '.' && $file != '..') {
  7. $time_file = filemtime('time_files/open_zip/' . $file);
  8. if ($time_file < ($time - 300))
  9. unlink('time_files/open_zip/' . $file);
  10. }
  11. }
  12. closedir($dir_clean);
  13. $sql->query("SELECT * FROM `down_files` WHERE `id` = '$id' AND (`type` = 2 OR `type` = 3) LIMIT 1");
  14. $res_down = $sql->fetch();
  15.  
  16. if ($sql->num_rows() == 0 || !is_file($res_down['dir'] . '/' . $res_down['name']) || ($res_down['type'] == 3 && !$admin)) {
  17. include H.'engine/includes/head.php';
  18. echo 'Файл не найден<br /><a href="index.php">К категориям</a>';
  19. include H.'engine/includes/foot.php';
  20. }
  21. if (isset($_GET['more'])) {
  22. $more = abs(intval($_GET['more']));
  23. $sql->query("SELECT * FROM `down_more` WHERE `id` = '$more' LIMIT 1");
  24. $res_more = $sql->fetch();
  25. if (!$sql->num_rows() || !is_file($res_down['dir'] . '/' . $res_more['name'])) {
  26. include H.'engine/includes/head.php';
  27. echo 'Файл не найден<br /><a href="index.php">К категориям</a>';
  28. include H.'engine/includes/foot.php';
  29. exit;
  30. }
  31. $file_open = $res_down['dir'] . '/' . $res_more['name'];
  32. $isset_more = '&amp;more=' . $more;
  33. $title_pages = $res_more['rus_name'];
  34. }
  35. else {
  36. $file_open = $res_down['dir'] . '/' . $res_down['name'];
  37. $title_pages = $res_down['rus_name'];
  38. $isset_more = '';
  39. }
  40.  
  41. $title_pages = htmlspecialchars(mb_substr($title_pages, 0, 20));
  42. $set['title'] = 'Просмотр архива &raquo; ' . (mb_strlen($res_down['rus_name']) > 20 ? $title_pages . '...' : $title_pages);
  43. include H.'engine/includes/head.php';
  44.  
  45. require_once H.'engine/classes/zip.php';
  46. $array = array('cgi', 'pl', 'asp', 'aspx', 'shtml', 'shtm', 'fcgi', 'fpl', 'jsp', 'py', 'htaccess', 'ini', 'php', 'php3', 'php4', 'php5', 'php6', 'phtml', 'phps');
  47.  
  48. if (!isset($_GET['file'])) {
  49. $zip = new PclZip($file_open);
  50. if (($list = $zip->listContent()) == 0) {
  51. echo 'Неудалось открыть архив или выбранный файл не являеться ZIP архивом<br /><a href="index.php?act=view&amp;id=' . $id . '">Назад</a>';
  52. include H.'engine/includes/foot.php';
  53. exit;
  54. }
  55. $list_size = $list_content = $save_list = null;
  56. for ($i = 0; $i < sizeof($list); $i++) {
  57. for (reset($list[$i]); $key = key($list[$i]); next($list[$i])) {
  58. $file_size = str_replace("--size:", "", strstr($list_content, "--size"));
  59. $list_size .= str_replace($file_size, $file_size . '|', $file_size);
  60. $list_content = "[$i]--$key:" . $list[$i][$key];
  61. $zip_file = str_replace("--filename:", "", strstr($list_content, "--filename"));
  62. $save_list .= str_replace($zip_file, $zip_file . '|', $zip_file);
  63. }
  64. }
  65. $file_size_two = explode("|", $list_size);
  66. echo '<div class="p_m">' . $res_down['name'] . '</div><div class="foot">Вы можете скачать отдельные файлы из этого архива или просмотреть его код</div>';
  67. $preview = explode("|", $save_list);
  68. $total = count($preview) - 1;
  69. $page = new page($total, $set['p_str']);
  70. $start = $page->start();
  71. if ($total > 0) {
  72. $end = $start + $set['p_str'];
  73. if ($end > $total)
  74. $end = $total;
  75. for ($i = $start; $i < $end; $i++) {
  76. echo ($i % 2) ? '<div class="p_m">' : '<div class="p_m">';
  77. $path = $preview[$i];
  78. $file_name = preg_replace("#.*[\\/]#", '', $path);
  79. $dir = preg_replace("#[\\/]?[^\\/]*$#", '', $path);
  80. $format = explode('.', $file_name);
  81. $format_file = strtolower($format[count($format) - 1]);
  82. echo '<b>' . ($i + 1) . ')</b> ' . $dir . '/' . mb_convert_encoding($file_name, "UTF-8", "Windows-1251");
  83. if ($file_size_two[$i] > 0)
  84. echo ' (' . size_file($file_size_two[$i]) . ')';
  85. if ($format_file)
  86. echo ' - <a href="index.php?act=open_zip&amp;id=' . $id . '&amp;file=' . rawurlencode($path) . '&amp;start=' . $start . $isset_more . '">' . (in_array($format_file, $array) ? 'код' : 'скачать') . '</a>';
  87. echo '</div>';
  88. }
  89. }
  90. else
  91. echo '<div class="err">Архив пуст</div>';
  92. echo '<div class="msg">Вес распакованного архива: ' . text::size_data(array_sum($file_size_two)) . '</div>';
  93. echo '<div class="menu">Всего файлов: ' . $total . '</div>';
  94. $page->display('index.php?act=open_zip&amp;id=' . $id . '&amp;');
  95. echo '<p><form action="index.php" method="get"><input type="hidden" value="open_zip" name="act" />
  96. <input type="hidden" value="' . $id . '" name="id" /><input type="text" name="page" size="2"/><input type="submit" value="К странице &gt;&gt;"/></form></p>';
  97. }
  98. else {
  99.  
  100. $FileName = rawurldecode(trim($_GET['file']));
  101. $format = explode('.', $FileName);
  102. $format_file = strtolower($format[count($format) - 1]);
  103. if (strpos($FileName, '..') !== false or strpos($FileName, './') !== false) {
  104. echo display_error('<a href="index.php?act=view&amp;id=' . $id . '">К файлу</a>');
  105. include H.'engine/includes/foot.php';
  106. exit;
  107. }
  108. $FileName = htmlspecialchars(trim($FileName), ENT_QUOTES, 'UTF-8');
  109. $FileName = strtr($FileName, array('&' => '', '$' => '', '>' => '', '<' => '', '~' => '', '`' => '', '#' => '', '*' => ''));
  110. $zip = new PclZip($file_open);
  111. $content = $zip->extract(PCLZIP_OPT_BY_NAME, $FileName, PCLZIP_OPT_EXTRACT_AS_STRING);
  112. $content = $content[0]['content'];
  113. $FileName = preg_replace("#.*[\\/]#si", "", $FileName);
  114. if (in_array($format_file, $array)) {
  115. $content_two = explode("\r\n", $content);
  116. echo '<div class="title"><b>' . mb_convert_encoding($FileName, "UTF-8", "Windows-1251") . '</b></div><div class="list1"><div class="phpcode">';
  117. $rus_simvol = array('а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ъ', 'ы', 'ь', 'э', 'ю', 'я', 'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К',
  118. 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я');
  119. for ($i = 0; $i < 66; $i++) {
  120. if (strstr($content, $rus_simvol[$i]) !== false)
  121. $UTF = 1;
  122. }
  123. $php_code = trim($content);
  124. $php_code = substr($php_code, 0, 2) != "<?" ? "<?php\n" . $php_code . "\n?>" : $php_code;
  125. echo isset($UTF) ? highlight_string($php_code, true) : highlight_string(iconv('windows-1251', 'utf-8', $php_code), true);
  126. echo '</div></div><div class="menu">Всего строк: ' . count($content_two) . '</div>';
  127. }
  128. else {
  129. $NewNameFile = strtr(htmlspecialchars(mb_convert_encoding($FileName, "UTF-8", "Windows-1251")), array(' ' => '_', '@' => '', '%' => ''));
  130. if (file_exists('time_files/open_zip/' . $NewNameFile)) {
  131. header('Location: time_files/open_zip/' . $NewNameFile);
  132. exit;
  133. }
  134. $NewFile = 'time_files/open_zip/' . $NewNameFile;
  135. $dir = @fopen($NewFile, "wb");
  136. if ($dir) {
  137. if (flock($dir, LOCK_EX)) {
  138. fwrite($dir, $content);
  139. flock($dir, LOCK_UN);
  140. }
  141. fclose($dir);
  142. header('Location: time_files/open_zip/' . $NewNameFile);
  143. }
  144. else
  145. echo display_error('Не удалось сохранить файл на сервере');
  146.  
  147. } //echo '<a href="index.php?act=open_zip&amp;id=' . $id . '&amp;page=' . ($page + 1) . '">Назад</a><br />';
  148. }
  149.  
  150. echo '<a href="index.php?act=view&amp;id=' . $id . '">К файлу</a>';
  151.  
  152. include H.'engine/includes/foot.php';