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

Размер файла: 4.87Kb
  1. <?php
  2. define('SHCMS', true);
  3. include_once'../system/inc/basic_settings.php';
  4. $shcmsengine['title'] = 'Просмотр архива';
  5.  
  6.  
  7. if (isset($_GET['id'])) {
  8. $id = abs(intval($_GET['id']));
  9. } else {
  10. $id = 0;
  11. }
  12. if (isset($_GET['start'])) {
  13. $start = abs(intval($_GET['start']));
  14. } else {
  15. $start = 0;
  16. }
  17.  
  18.  
  19. switch ($act)
  20. {
  21. case '':
  22. include_once'../template/head.php';
  23. $file_arhiv = mysql_fetch_array(mysql_query("SELECT * FROM `download_file` WHERE `id`='$id'"));
  24.  
  25. /*
  26. Проверка на существования файла
  27. */
  28. if (($file_arhiv == null) ||(!is_file('files_obmen/'.$file_arhiv['name']))) {
  29. echo "<div class='errors'>Файл не найден или был удален.</div>";
  30. include_once'../template/foot.php';
  31. exit();}
  32. /*
  33. Объявляем клаcc PclZip
  34. */
  35. $zip = new PclZip('files_obmen/'.$file_arhiv['name']);
  36.  
  37.  
  38. if (($list = $zip->listContent()) == 0) {die("Возникла ошибка: " . $zip->errorInfo(true));}
  39.  
  40. for ($i = 0; $i < sizeof($list); $i++) {
  41. for (reset($list[$i]); $key = key($list[$i]); next($list[$i])) {
  42. $zipdirarhive = strstr($listcontent, "--size");
  43. $zipdirarhive = ereg_replace("--size:", "", $zipdirarhive);
  44. $zipdirarhive = @ ereg_replace("$zipdirarhive", "$zipdirarhive|", $zipdirarhive);
  45. $sizelist .= "$zipdirarhive";
  46. $listcontent = "[$i]--$key:" . $list[$i][$key] . "";
  47. $arhive_list = strstr($listcontent, "--filename");
  48. $arhive_list = ereg_replace("--filename:", "", $arhive_list);
  49. $arhive_list = ereg_replace("$arhive_list", "$arhive_list|", $arhive_list);
  50. $savelist .= "$arhive_list";
  51. }
  52. }
  53. $sizefiles2 = explode("|", $sizelist);
  54. $sizelist2 = array_sum($sizefiles2);
  55. $obkb = round($sizelist2 / 1024, 2);
  56.  
  57. $preview = "$savelist";
  58. $preview = explode("|", $preview);
  59. $count = count($preview) - 1;
  60. echo "<b>$arch</b>Файлов всего: $count<hr/>";
  61. if (empty ($_GET['page'])) {
  62. $page = 1;
  63. }
  64. else {
  65. $page = intval($_GET['page']);
  66. }
  67. $start = $page * 10 - 10;
  68. if ($count < $start + 10) {
  69. $end = $count;
  70. }
  71. else { $end = $start + 10;}
  72. for ($i = $start; $i < $end; $i++) {
  73. $sizefiles = explode("|", $sizelist);
  74. $selectfile = explode("|", $savelist);
  75. $path = $selectfile[$i];
  76. $filename = ereg_replace(".*[\\/]", "", $path);
  77. $zdir = ereg_replace("[\\/]?[^\\/]*$", "", $path);
  78. $tfl = strtolower(size($filename));
  79. $arrext = array('.xml', '.wml', '.asp', '.aspx', '.shtml', '.htm', '.phtml', '.html', '.php', '.htt', '.dat', '.tpl', '.htaccess', '.pl', '.js', '.jsp', '.css', '.txt', '.sql', '.gif', '.png', '.bmp', '.wbmp', '.jpg', '.jpeg');
  80.  
  81. if (in_array($tfl, $arrext)) {
  82. echo "$zdir/$filename";
  83. }
  84. else {
  85. echo '<b>'.$zdir.'/ </b><a href="zip.php?act=preview&amp;id='.$id.'&amp;view='.$i.'&amp;start='.$start.'&amp;">'.$filename.'</a>';//Выводит файлы
  86. }
  87. if ($sizefiles[$i] != "0") {
  88. $sizekb = round($sizefiles[$i] / 1024, 2);
  89. echo " ($sizekb кб)";
  90. }
  91.  
  92. echo '<br/>';
  93. }
  94. include_once'../template/foot.php';
  95. break;
  96.  
  97.  
  98. case "preview":
  99. include_once '../template/head.php';
  100. $shcmsengine['title'] = 'Просмотр файлов';
  101. $view = abs(intval($_GET['view']));
  102.  
  103. $downs = mysql_fetch_array(mysql_query("SELECT * FROM `download_file` WHERE `id`='$id'"));
  104. $shcmsengine['title'] = ''.$downs['names'].'';
  105. if ($downs > 0) {
  106. $zip = new PclZip('files_obmen/'.$downs['name']);
  107.  
  108. $content = $zip -> extract(PCLZIP_OPT_BY_INDEX, $view, PCLZIP_OPT_EXTRACT_AS_STRING);
  109. if (!empty($content)) {
  110. $filecontent = $content[0]['content'];
  111. $filename = $content[0]['filename'];
  112.  
  113. echo '<img src="icons/zip.png" alt="image" /> <b>'.$downs['name'].'</b><br /><br />';
  114.  
  115. echo '<b>'.$filename.'</b> ('.size($content[0]['size']).')<hr />';
  116.  
  117. if (!preg_match("/\.(gif|png|bmp|wbmp|jpg|jpeg)$/", $filename)) {
  118. if ($content[0]['size'] > 0) {
  119. if (utf($filecontent)) {
  120. echo '<div class="d">'.bbcode::printCode($filecontent, 1).'</div><br />';
  121. } else {
  122. echo '<div class="d">'.bbcode::printCode(win_utf8($filecontent), 1).'</div><br />';
  123. }
  124. } else {
  125. echo 'Данный файл пустой!';
  126. }
  127. } else {
  128. if (!empty($_GET['img'])) {
  129. $ext = strtolower(substr($filename, strrpos($filename, '.') + 1));
  130.  
  131. ob_end_clean();
  132. ob_clean();
  133.  
  134. header("Content-type: image/$ext");
  135. header("Content-Length: ".strlen($filecontent));
  136. header('Content-Disposition: inline; filename="'.$filename.'";');
  137.  
  138. echo $filecontent;
  139. exit;
  140. }
  141.  
  142. echo '<img src="zip.php?act=preview&amp;id='.$id.'&amp;view='.$view.'&amp;img=1" alt="image" /><br /><br />';
  143. }
  144. } else {
  145. echo'Ошибка! Не удалось извлечь файл!';
  146. }
  147. } else {
  148. echo'Ошибка! Данного файла не существует!';
  149. }
  150.  
  151. echo ' <a href="zip.php?id='.$id.'&amp;start='.$start.'&amp;'.SID.'">Вернуться</a><br />';
  152. include_once'../template/foot.php';
  153. break;
  154. }
  155.  
  156.  
  157. ?>