UploadProgress.class.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Provides upload functionalities for the import plugins
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. if (! defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. /* Get the transformations interface */
  12. require_once 'libraries/plugins/UploadInterface.int.php';
  13. /**
  14. * Implementation for upload progress
  15. *
  16. * @package PhpMyAdmin
  17. */
  18. class UploadProgress implements UploadInterface
  19. {
  20. /**
  21. * Gets the specific upload ID Key
  22. *
  23. * @return string ID Key
  24. */
  25. public static function getIdKey()
  26. {
  27. return 'UPLOAD_IDENTIFIER';
  28. }
  29. /**
  30. * Returns upload status.
  31. *
  32. * This is implementation for upload progress
  33. *
  34. * @param string $id upload id
  35. *
  36. * @return array|null
  37. */
  38. public static function getUploadStatus($id)
  39. {
  40. global $SESSION_KEY;
  41. if (trim($id) == "") {
  42. return null;
  43. }
  44. if (! array_key_exists($id, $_SESSION[$SESSION_KEY])) {
  45. $_SESSION[$SESSION_KEY][$id] = array(
  46. 'id' => $id,
  47. 'finished' => false,
  48. 'percent' => 0,
  49. 'total' => 0,
  50. 'complete' => 0,
  51. 'plugin' => UploadProgress::getIdKey()
  52. );
  53. }
  54. $ret = $_SESSION[$SESSION_KEY][$id];
  55. if (! PMA_import_progressCheck() || $ret['finished']) {
  56. return $ret;
  57. }
  58. $status = uploadprogress_get_info($id);
  59. if ($status) {
  60. if ($status['bytes_uploaded'] == $status['bytes_total']) {
  61. $ret['finished'] = true;
  62. } else {
  63. $ret['finished'] = false;
  64. }
  65. $ret['total'] = $status['bytes_total'];
  66. $ret['complete'] = $status['bytes_uploaded'];
  67. if ($ret['total'] > 0) {
  68. $ret['percent'] = $ret['complete'] / $ret['total'] * 100;
  69. }
  70. } else {
  71. $ret = array(
  72. 'id' => $id,
  73. 'finished' => true,
  74. 'percent' => 100,
  75. 'total' => $ret['total'],
  76. 'complete' => $ret['total'],
  77. 'plugin' => UploadProgress::getIdKey()
  78. );
  79. }
  80. $_SESSION[$SESSION_KEY][$id] = $ret;
  81. return $ret;
  82. }
  83. }
  84. ?>