2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Import progress bar backend
8 declare(strict_types
=1);
11 use PhpMyAdmin\Display\ImportAjax
;
13 if (! defined('ROOT_PATH')) {
14 define('ROOT_PATH', __DIR__
. DIRECTORY_SEPARATOR
);
17 /* PHP 5.4 stores upload progress data only in the default session.
18 * After calling session_name(), we won't find the progress data anymore.
20 * https://bugs.php.net/bug.php?id=64075
22 * The bug should be somewhere in
23 * https://github.com/php/php-src/blob/master/ext/session/session.c#L2342
25 * Until this is fixed, we need to load the default session to load the data,
26 * export the upload progress information from there,
27 * and re-import after switching to our session.
29 * However, since https://github.com/phpmyadmin/phpmyadmin/commit/063a2d99
30 * we have deactivated this feature, so the corresponding code is now
35 if (ini_get('session.upload_progress.enabled')) {
37 $sessionupload = array();
38 define('UPLOAD_PREFIX', ini_get('session.upload_progress.prefix'));
41 foreach ($_SESSION as $key => $value) {
42 // only copy session-prefixed data
43 if (substr($key, 0, strlen(UPLOAD_PREFIX))
45 $sessionupload[$key] = $value;
48 // PMA will kill all variables, so let's use a constant
49 define('SESSIONUPLOAD', serialize($sessionupload));
50 session_write_close();
52 // The cookie name is not good anymore since PR #15273
53 session_name('phpMyAdmin');
54 session_id($_COOKIE['phpMyAdmin']);
58 define('PMA_MINIMUM_COMMON', 1);
60 require_once ROOT_PATH
. 'libraries/common.inc.php';
65 ) = ImportAjax
::uploadProgressSetup();
68 if (defined('SESSIONUPLOAD')) {
69 // write sessionupload back into the loaded PMA session
71 $sessionupload = unserialize(SESSIONUPLOAD);
72 foreach ($sessionupload as $key => $value) {
73 $_SESSION[$key] = $value;
76 // remove session upload data that are not set anymore
77 foreach ($_SESSION as $key => $value) {
78 if (substr($key, 0, strlen(UPLOAD_PREFIX))
80 && ! isset($sessionupload[$key])
82 unset($_SESSION[$key]);
88 // $_GET["message"] is used for asking for an import message
89 if (isset($_GET["message"]) && $_GET["message"]) {
90 // AJAX requests can't be cached!
91 Core
::noCacheHeader();
93 header('Content-type: text/html');
95 // wait 0.3 sec before we check for $_SESSION variable,
96 // which is set inside import.php
99 $maximumTime = ini_get('max_execution_time');
101 // wait until message is available
102 while ($_SESSION['Import_message']['message'] == null) {
103 // close session before sleeping
104 session_write_close();
106 usleep(250000); // 0.25 sec
110 if ((time() - $timestamp) > $maximumTime) {
111 $_SESSION['Import_message']['message'] = PhpMyAdmin\Message
::error(
112 __('Could not load the progress of the import.')
118 echo $_SESSION['Import_message']['message'];
119 echo '<fieldset class="tblFooters">' , "\n";
120 echo ' [ <a href="' , $_SESSION['Import_message']['go_back_url']
121 . '">' , __('Back') , '</a> ]' , "\n";
122 echo '</fieldset>' , "\n";
124 ImportAjax
::status($_GET["id"]);