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

Размер файла: 5.02Kb
  1. <?php
  2.  
  3. $dir_clean = opendir('time_files/created_java/files');
  4. while ($file = readdir($dir_clean)) {
  5. if ($file != 'index.php' && $file != '.htaccess' && $file != '.' && $file != '..') {
  6. $time_file = filemtime('time_files/created_java/files/' . $file);
  7. if ($time_file < ($time - 300))
  8. unlink('time_files/created_java/files/' . $file);
  9. }
  10. }
  11. closedir($dir_clean);
  12. $req_down = $sql->query("SELECT * FROM `down_files` WHERE `id` = '$id' AND (`type` = 2 OR `type` = 3) LIMIT 1");
  13. $res_down = $sql->fetch();
  14. $format_file = format($res_down['name']);
  15.  
  16. if ($sql->num_rows() == 0 || !is_file($res_down['dir'] . '/' . $res_down['name']) || $format_file != 'txt' || ($res_down['type'] == 3 && !$admin)) {
  17. include H.'engine/includes/head.php';
  18. echo Core::msg_show('Файл не найден<br /><a href="index.php">К категориям</a>');
  19. include H.'engine/includes/foot.php';
  20. }
  21.  
  22. if (isset($_GET['more'])) {
  23. $more = abs(intval($_GET['more']));
  24. $req_more = $sql->query("SELECT * FROM `down_more` WHERE `id` = '$more' LIMIT 1");
  25. $res_more = $sql->fetch();
  26. $format_file = format($res_more['name']);
  27. if (!$sql->num_rows() || !is_file($res_down['dir'] . '/' . $res_more['name']) || $format_file != 'txt') {
  28. include H.'engine/includes/head.php';
  29. echo Core::msg_show('Файл не найден<br /><a href="index.php">К категориям</a>');
  30. include H.'engine/includes/foot.php';
  31. }
  32. $down_file = $res_down['dir'] . '/' . $res_more['name'];
  33. $title_pages = $res_more['rus_name'];
  34. $txt_file = $res_more['name'];
  35. }
  36. else {
  37. $down_file = $res_down['dir'] . '/' . $res_down['name'];
  38. $title_pages = $res_down['rus_name'];
  39. $txt_file = $res_down['name'];
  40. }
  41.  
  42. if (!isset($_SESSION['down_' . $id])) {
  43. $sql->query("UPDATE `down_files` SET `field`=`field`+1 WHERE `id`='$id'");
  44. $_SESSION['down_' . $id] = 1;
  45. }
  46.  
  47. $file = str_replace('.' . $format_file, '', $txt_file);
  48. $name = str_replace('.' . $format_file, '', $txt_file);
  49. $tmp = 'time_files/created_java/files/' . $name . '.jar';
  50. $tmp_jad = 'time_files/created_java/files/' . $name . '.jar.jad';
  51. if (!file_exists($tmp)) {
  52. $midlet_name = mb_substr($res_down['rus_name'], 0, 10);
  53. $midlet_name = iconv('UTF-8', 'windows-1251', $midlet_name);
  54. $book_text = file_get_contents($res_down['dir'] . '/' . $res_down['name']);
  55. $charset_text = strtolower(mb_detect_encoding($book_text, 'UTF-8, windows-1251'));
  56. if ($charset_text != 'windows-1251')
  57. $book_text = iconv('utf-8', 'windows-1251', $book_text);
  58. $files = fopen("time_files/created_java/java/textfile.txt", 'w+');
  59. flock($files, LOCK_EX);
  60. $book_name = iconv('UTF-8', 'windows-1251', $res_down['rus_name']);
  61. $result = PHP_EOL . $book_name . PHP_EOL . PHP_EOL . '----------' . PHP_EOL . PHP_EOL . trim($book_text) . PHP_EOL . PHP_EOL . 'Downloaded from '. $_SERVER['HTTP_HOST'];
  62. fputs($files, $result);
  63. flock($files, LOCK_UN);
  64. fclose($files);
  65. $manifest_text = 'Manifest-Version: 1.0
  66. MIDlet-1: Файл #' . $id . ', , br.BookReader
  67. MIDlet-Name: $tmp_jad
  68. MIDlet-Vendor: Tadochi
  69. MIDlet-Version: 1.5.3
  70. MIDletX-No-Command: true
  71. MIDletX-LG-Contents: true
  72. MicroEdition-Configuration: CLDC-1.0
  73. MicroEdition-Profile: MIDP-1.0
  74. TCBR-Platform: Generic version (all phones)';
  75. $files = fopen("time_files/created_java/java/META-INF/MANIFEST.MF", 'w+');
  76. flock($files, LOCK_EX);
  77. fputs($files, $manifest_text);
  78. flock($files, LOCK_UN);
  79. fclose($files);
  80. Core::get('zip');
  81. $archive = new PclZip($tmp);
  82. $list = $archive->create('time_files/created_java/java', PCLZIP_OPT_REMOVE_PATH, 'time_files/created_java/java');
  83. if (!file_exists($tmp)) {
  84. include H.'engine/includes/head.php';
  85. echo Core::msg_show('Ошибка создания JAR файла');
  86. include H.'engine/includes/foot.php';
  87. }
  88. }
  89. if (!file_exists($tmp_jad)) {
  90. $filesize = filesize($tmp);
  91. $jad_text = 'Manifest-Version: 1.0
  92. MIDlet-1: Файл #' . $id . ', , br.BookReader
  93. MIDlet-Name: Файл #' . $id . '
  94. MIDlet-Vendor: Tadochi
  95. MIDlet-Version: 1.5.3
  96. MIDletX-No-Command: true
  97. MIDletX-LG-Contents: true
  98. MicroEdition-Configuration: CLDC-1.0
  99. MicroEdition-Profile: MIDP-1.0
  100. TCBR-Platform: Generic version (all phones)
  101. MIDlet-Jar-Size: ' . $filesize . '
  102. MIDlet-Jar-URL: ' . $home . '/' . $dir_load . '/' . $tmp;
  103. $files = fopen($tmp_jad, 'w+');
  104. flock($files, LOCK_EX);
  105. fputs($files, $jad_text);
  106. flock($files, LOCK_UN);
  107. fclose($files);
  108. }
  109.  
  110.  
  111. include H.'engine/includes/head.php';
  112.  
  113.  
  114. echo '<div class="p_t"><b>' . text::output($title_pages) . '</b></div>';
  115. echo '<div class="menu">Скачать: <a href="' . text::output($tmp) . '">JAR</a> | <a href="' . text::output($tmp_jad) . '">JAD</a></div>';
  116. echo '<div class="menu">Файлы будут доступны для скачивания в течение 5 минут</div>';
  117. echo '<div class="p_t"><a href="index.php?act=view&amp;id=' . $id . '">К файлу</a></div>';
  118.  
  119. ?>