Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / plugins / import / upload / UploadSession.class.php
blob36404133eefb192a873cef093b749ec327b92aee
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Provides upload functionalities for the import plugins
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /* Get the transformations interface */
13 require_once 'libraries/plugins/UploadInterface.int.php';
15 /**
16 * Implementation for session
18 * @package PhpMyAdmin
20 class UploadSession implements UploadInterface
22 /**
23 * Gets the specific upload ID Key
25 * @return string ID Key
27 public static function getIdKey()
29 return ini_get('session.upload_progress.name');
32 /**
33 * Returns upload status.
35 * This is implementation for session.upload_progress in PHP 5.4+.
37 * @param string $id upload id
39 * @return array|null
41 public static function getUploadStatus($id)
43 global $SESSION_KEY;
45 if (trim($id) == '') {
46 return null;
49 if (! array_key_exists($id, $_SESSION[$SESSION_KEY])) {
50 $_SESSION[$SESSION_KEY][$id] = array(
51 'id' => $id,
52 'finished' => false,
53 'percent' => 0,
54 'total' => 0,
55 'complete' => 0,
56 'plugin' => UploadSession::getIdKey()
59 $ret = $_SESSION[$SESSION_KEY][$id];
61 if (! PMA_import_sessionCheck() || $ret['finished']) {
62 return $ret;
65 $status = false;
66 $sessionkey = ini_get('session.upload_progress.prefix') . $id;
68 if (isset($_SESSION[$sessionkey])) {
69 $status = $_SESSION[$sessionkey];
72 if ($status) {
73 $ret['finished'] = $status['done'];
74 $ret['total'] = $status['content_length'];
75 $ret['complete'] = $status['bytes_processed'];
77 if ($ret['total'] > 0) {
78 $ret['percent'] = $ret['complete'] / $ret['total'] * 100;
80 } else {
81 $ret = array(
82 'id' => $id,
83 'finished' => true,
84 'percent' => 100,
85 'total' => $ret['total'],
86 'complete' => $ret['total'],
87 'plugin' => UploadSession::getIdKey()
91 $_SESSION[$SESSION_KEY][$id] = $ret;
93 return $ret;