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

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