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

/components/com_hwdmediashare/libraries/uber/ubr_get_progress.php

https://gitlab.com/ppapadatis/Videolearn
PHP | 113 lines | 58 code | 20 blank | 35 comment | 25 complexity | 9ba40243b5f86a8bd49c12bd9649da74 MD5 | raw file
  1. <?php
  2. //******************************************************************************************************
  3. // ATTENTION: THIS FILE HEADER MUST REMAIN INTACT. DO NOT DELETE OR MODIFY THIS FILE HEADER.
  4. //
  5. // Name: ubr_get_progress.php
  6. // Revision: 1.2
  7. // Date: 2/18/2008 5:37:18 PM
  8. // Link: http://uber-uploader.sourceforge.net
  9. // Initial Developer: Peter Schmandra
  10. // Description: Gather stats on an existing upload
  11. //
  12. // Licence:
  13. // The contents of this file are subject to the Mozilla Public
  14. // License Version 1.1 (the "License"); you may not use this file
  15. // except in compliance with the License. You may obtain a copy of
  16. // the License at http://www.mozilla.org/MPL/
  17. //
  18. // Software distributed under the License is distributed on an "AS
  19. // IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  20. // implied. See the License for the specific language governing
  21. // rights and limitations under the License.
  22. //
  23. //***************************************************************************************************************
  24. //***************************************************************************************************************
  25. // * ATTENTION * If you need to debug this file, set the $DEBUG_AJAX = 1 in ubr_ini.php
  26. // and use the showDebugMessage function. eg. showDebugMessage("Upload ID = $UPLOAD_ID<br>");
  27. //***************************************************************************************************************
  28. //******************************************************************************************************************************
  29. // The following possible query string formats are assumed
  30. //
  31. // 1. ?upload_id=32_alpha_numeric_string&start_time=unix_time&total_upload_size=total_upload_size_in_bytes&rnd_id=random_number
  32. // 2. ?about=1
  33. //******************************************************************************************************************************
  34. $THIS_VERSION = "1.2"; // Version of this file
  35. $UPLOAD_ID = ''; // Initialize upload id
  36. require 'ubr_ini.php';
  37. require 'ubr_lib.php';
  38. if($PHP_ERROR_REPORTING){ error_reporting(E_ALL); }
  39. ob_start();
  40. if(preg_match("/^[a-zA-Z0-9]{32}$/", $_GET['upload_id']) && isset($_GET['start_time']) && isset($_GET['total_upload_size'])){ $UPLOAD_ID = $_GET['upload_id']; }
  41. elseif(isset($_GET['about']) && $_GET['about'] == 1){ kak("<u><b>UBER UPLOADER GET PROGRESS</b></u><br>UBER UPLOADER VERSION = <b>" . $UBER_VERSION . "</b><br>UBR_GET_PROGRESS = <b>" . $THIS_VERSION . "<b>", 1, __LINE__); }
  42. else{ kak("ERROR: Invalid parameters passed<br>", 1, __LINE__); }
  43. $read_status = GetBytesRead($TEMP_DIR, $UPLOAD_ID);
  44. if($read_status->active && $read_status->bytes_uploaded < $_GET['total_upload_size']){
  45. $lapsed_time = time() - $_GET['start_time'];
  46. if($DEBUG_AJAX){ showDebugMessage("Set progress: bytes uploaded=" . $read_status->bytes_uploaded . " lapsed time=" . $lapsed_time . " uploaded files=" . $read_status->uploaded_files); }
  47. setProgressStatus($read_status->bytes_uploaded, $lapsed_time, $read_status->uploaded_files);
  48. getProgressStatus($GET_PROGRESS_SPEED);
  49. }
  50. else{
  51. stopDataLoop();
  52. hideProgressBar();
  53. if($DEBUG_AJAX){
  54. if(!$read_status->active && $read_status->is_dir_error && !$embedded_upload_results){
  55. showDebugMessage("<font color='green'>WARNING</font>: Cannot find upload temp directory<br>");
  56. }
  57. elseif(!$read_status->active && $read_status->open_dir_error && !$embedded_upload_results){
  58. showDebugMessage("<font color='green'>WARNING</font>: Cannot open upload temp directory<br>");
  59. }
  60. }
  61. }
  62. //////////////////////////////////////////////////////////FUNCTIONS //////////////////////////////////////////////////////////////////
  63. //Class to store read info
  64. class ReadStatus{
  65. var $is_dir_error = 0;
  66. var $open_dir_error = 0;
  67. var $active = 0;
  68. var $uploaded_files = 0;
  69. var $bytes_uploaded = 0;
  70. }
  71. // Return the current size of the $_GET['temp_dir_sid'] - flength file size.
  72. function GetBytesRead($temp_dir, $upload_id){
  73. $read_status = new ReadStatus;
  74. $temp_upload_dir = $temp_dir . $upload_id . '.dir';
  75. $flength_file = $upload_id . '.flength';
  76. if(is_dir($temp_upload_dir) && is_file($temp_upload_dir . '/' . $flength_file)){
  77. if($handle = opendir($temp_upload_dir)){
  78. while(false !== ($file_name = readdir($handle))){
  79. if(($file_name != '.') && ($file_name != '..') && ($file_name != $flength_file)){
  80. $read_status->bytes_uploaded += filesize($temp_upload_dir . '/' . $file_name);
  81. $read_status->uploaded_files++;
  82. }
  83. }
  84. closedir($handle);
  85. $read_status->active = 1;
  86. if($read_status->uploaded_files > 0){ $read_status->uploaded_files -= 1; }
  87. }
  88. else{ $read_status->open_dir_error = 1; }
  89. }
  90. else{ $read_status->is_dir_error = 1; }
  91. return $read_status;
  92. }
  93. ?>