PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/album_nuffload_pbar.php

http://github.com/MightyGorgon/icy_phoenix
PHP | 183 lines | 126 code | 17 blank | 40 comment | 17 complexity | 596595a53540c7b0f0820f2f42f0ab55 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package Icy Phoenix
  5. * @version $Id$
  6. * @copyright (c) 2008 Icy Phoenix
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. *
  12. * @Extra credits for this file
  13. * Nuffmon (nuffmon@hotmail.com)
  14. *
  15. */
  16. define('IN_ICYPHOENIX', true);
  17. if (!defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './');
  18. if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
  19. include(IP_ROOT_PATH . 'common.' . PHP_EXT);
  20. // Start session management
  21. $user->session_begin();
  22. $auth->acl($user->data);
  23. $user->setup();
  24. // End session management
  25. // Get general album information
  26. include(ALBUM_MOD_PATH . 'album_common.' . PHP_EXT);
  27. function hms($sec)
  28. {
  29. $thetime = str_pad(intval(intval($sec) / 3600), 2, "0", STR_PAD_LEFT) . ":" . str_pad(intval(($sec / 60) % 60), 2, "0", STR_PAD_LEFT) . ":" . str_pad(intval($sec % 60), 2, "0", STR_PAD_LEFT) ;
  30. return $thetime;
  31. }
  32. // Check session_id and monitor upload or quit
  33. if(isset($_REQUEST['sessionid']))
  34. {
  35. // Set unlimited timeout
  36. set_time_limit(0);
  37. $start_time = time(); //Set start time as now
  38. $sessionid = $_REQUEST['sessionid'];
  39. // Path to data files
  40. $info_file = $album_config['path_to_bin'] . "tmp/$sessionid"."_flength";
  41. $data_file = $album_config['path_to_bin'] . "tmp/$sessionid"."_postdata";
  42. //$signal_file = $album_config['path_to_bin'] . "tmp/$sessionid"."_signal";
  43. // Dump page header
  44. $gen_simple_header = true;
  45. $meta_content['page_title'] = $lang['upload_in_progress'];
  46. $meta_content['description'] = '';
  47. $meta_content['keywords'] = '';
  48. if(!$album_config['simple_format'])
  49. {
  50. page_header();
  51. }
  52. // Load template
  53. $template->set_filenames(array('body' => 'album_nuffload_pbar_body.tpl'));
  54. // Load template variable
  55. $template->assign_vars(array(
  56. 'L_ALBUM' => $lang['album'],
  57. 'L_UPLOAD_PIC' => $lang['Upload_Pic'],
  58. 'L_UPLOAD_IN_PROGRESS' => $lang['upload_in_progress'],
  59. 'L_TIME_ELAPSED' => $lang['time_elapsed'],
  60. 'L_TIME_REMAINING' => $lang['time_remaining'],
  61. 'L_NUFFLOAD_VERSION' => 'v1.4.2'
  62. )
  63. );
  64. page_footer(false);
  65. $db->sql_close();
  66. // Loop/monitor filesize until complete
  67. $upload_started = false;
  68. for(;$percent_done < 100;)
  69. {
  70. // Open info file to find filesize
  71. // info file created by perl script
  72. if (intval($total_size) <= 0)
  73. {
  74. if ($fp = @fopen($info_file, 'r'))
  75. {
  76. $fd = @fread($fp, 1000);
  77. @fclose($fp);
  78. $total_size = $fd;
  79. }
  80. }
  81. $time_elapsed = time()- $start_time;
  82. $previous_size = $current_size;
  83. @clearstatcache();
  84. if (@file_exists($data_file))
  85. {
  86. $current_size = @filesize($data_file);
  87. $upload_started = true;
  88. }
  89. else
  90. {
  91. if ($upload_started)
  92. {
  93. ?>
  94. <script type="text/javascript">
  95. <!--
  96. top.close();
  97. // -->
  98. </script>
  99. <?php
  100. exit;
  101. }
  102. }
  103. // This section checks for no activity and stops processing
  104. if ($previous_size < $current_size)
  105. {
  106. $activity_time = 0;
  107. }
  108. else
  109. {
  110. $activity_time++;
  111. }
  112. if ($activity_time >= $album_config['max_pause'])
  113. {
  114. ?>
  115. <script type="text/javascript">
  116. <!--
  117. top.close();
  118. // -->
  119. </script>
  120. <?php
  121. exit;
  122. }
  123. // Calculate progress values if upload started.
  124. if ($current_size > 0 && $time_elapsed > 0)
  125. {
  126. $percent_done = sprintf("%.0f",($current_size / $total_size) * 100);
  127. $speed = ($current_size / $time_elapsed);
  128. if ($speed == 0) {$speed = 1024;}
  129. $time_remain_str = hms(($total_size-$current_size) / $speed);
  130. $time_elapsed_str = hms($time_elapsed);
  131. }
  132. if ($percent_done < 1)
  133. {
  134. $percent_done = 1;
  135. }
  136. ?>
  137. <script type="text/javascript">
  138. <!--
  139. document.getElementById("progress1").width = "<?php print $percent_done; ?>%";
  140. document.getElementById("progress2").innerHTML = '<? echo $current_size; ?>/<? echo $total_size; ?> (<? echo $percent_done; ?>%) <? echo printf("%.2f",$speed/1024); ?> kbit/s<br /><? echo $lang['time_elapsed'] . ": " . $time_elapsed_str; ?><br /><? echo $lang['time_remaining'] . ": " . $time_remain_str; ?>';
  141. // -->
  142. </script>
  143. <?php
  144. ob_flush();
  145. flush();
  146. sleep(1);
  147. }
  148. // Now we have finished we can delete the data files
  149. /*
  150. @unlink($info_file);
  151. @unlink($data_file);
  152. @unlink($signal_file);
  153. */
  154. // Send javascript to close form if required
  155. if ($album_config['close_on_finish'])
  156. {
  157. ?>
  158. <script type="text/javascript">
  159. <!--
  160. top.close();
  161. // -->
  162. </script>
  163. <?php
  164. }
  165. }
  166. ?>