display_import_ajax.lib.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Handles plugins that show the upload progress
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. if (! defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. /**
  12. * constant for differenciating array in $_SESSION variable
  13. */
  14. $SESSION_KEY = '__upload_status';
  15. /**
  16. * sets default plugin for handling the import process
  17. */
  18. $_SESSION[$SESSION_KEY]["handler"] = "";
  19. /**
  20. * unique ID for each upload
  21. */
  22. $upload_id = uniqid("");
  23. /**
  24. * list of available plugins
  25. *
  26. * Each plugin has own checkfunction in display_import_ajax.lib.php
  27. * and own file with functions in upload_#KEY#.php
  28. */
  29. $plugins = array(
  30. // PHP 5.4 session-based upload progress is problematic, see bug 3964
  31. //"session",
  32. "progress",
  33. "apc",
  34. "noplugin"
  35. );
  36. // select available plugin
  37. foreach ($plugins as $plugin) {
  38. $check = "PMA_import_" . $plugin . "Check";
  39. if ($check()) {
  40. $upload_class = "Upload" . ucwords($plugin);
  41. $_SESSION[$SESSION_KEY]["handler"] = $upload_class;
  42. include_once "plugins/import/upload/" . $upload_class . ".class.php";
  43. break;
  44. }
  45. }
  46. /**
  47. * Checks if APC bar extension is available and configured correctly.
  48. *
  49. * @return boolean true if APC extension is available and if rfc1867 is enabled,
  50. * false if it is not
  51. */
  52. function PMA_import_apcCheck()
  53. {
  54. if (! extension_loaded('apc')
  55. || ! function_exists('apc_fetch')
  56. || ! function_exists('getallheaders')
  57. ) {
  58. return false;
  59. }
  60. return (ini_get('apc.enabled') && ini_get('apc.rfc1867'));
  61. }
  62. /**
  63. * Checks if UploadProgress bar extension is available.
  64. *
  65. * @return boolean true if UploadProgress extension is available,
  66. * false if it is not
  67. */
  68. function PMA_import_progressCheck()
  69. {
  70. if (! function_exists("uploadprogress_get_info")
  71. || ! function_exists('getallheaders')
  72. ) {
  73. return false;
  74. }
  75. return true;
  76. }
  77. /**
  78. * Checks if PHP 5.4 session upload-progress feature is available.
  79. *
  80. * @return boolean true if PHP 5.4 session upload-progress is available,
  81. * false if it is not
  82. */
  83. function PMA_import_sessionCheck()
  84. {
  85. if (PMA_PHP_INT_VERSION < 50400
  86. || ! ini_get('session.upload_progress.enabled')
  87. ) {
  88. return false;
  89. }
  90. return true;
  91. }
  92. /**
  93. * Default plugin for handling import.
  94. * If no other plugin is available, noplugin is used.
  95. *
  96. * @return boolean true
  97. */
  98. function PMA_import_nopluginCheck()
  99. {
  100. return true;
  101. }
  102. /**
  103. * The function outputs json encoded status of uploaded.
  104. * It uses PMA_getUploadStatus, which is defined in plugin's file.
  105. *
  106. * @param string $id ID of transfer, usually $upload_id
  107. * from display_import_ajax.lib.php
  108. *
  109. * @return void
  110. */
  111. function PMA_importAjaxStatus($id)
  112. {
  113. header('Content-type: application/json');
  114. echo json_encode(
  115. call_user_func(
  116. $_SESSION[$GLOBALS['SESSION_KEY']]['handler'] . '::getUploadStatus',
  117. $id
  118. )
  119. );
  120. }
  121. ?>