Merge branch 'master' of git://phpmyadmin.git.sourceforge.net/gitroot/phpmyadmin...
[phpmyadmin/thilanka.git] / libraries / import / upload / uploadprogress.php
blobd5c361c1d41372904b13a8dffe63bb7f4a291ccc
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package phpMyAdmin
6 */
7 if (! defined('PHPMYADMIN')) {
8 exit;
11 $ID_KEY = "UPLOAD_IDENTIFIER";
13 /**
14 * Returns upload status.
16 * This is implementation for uploadprogress extension.
18 * @param string $id
19 * @return array|null
21 function PMA_getUploadStatus($id)
23 global $SESSION_KEY;
24 global $ID_KEY;
26 if (trim($id) == "") {
27 return null;
30 if (! array_key_exists($id, $_SESSION[$SESSION_KEY])) {
31 $_SESSION[$SESSION_KEY][$id] = array(
32 'id' => $id,
33 'finished' => false,
34 'percent' => 0,
35 'total' => 0,
36 'complete' => 0,
37 'plugin' => $ID_KEY
40 $ret = $_SESSION[$SESSION_KEY][$id];
42 if (! PMA_import_uploadprogressCheck() || $ret['finished']) {
43 return $ret;
46 $status = uploadprogress_get_info($id);
48 if ($status) {
49 if ($status['bytes_uploaded'] == $status['bytes_total']) {
50 $ret['finished'] = true;
51 } else {
52 $ret['finished'] = false;
54 $ret['total'] = $status['bytes_total'];
55 $ret['complete'] = $status['bytes_uploaded'];
57 if ($ret['total'] > 0) {
58 $ret['percent'] = $ret['complete'] / $ret['total'] * 100;
60 } else {
61 $ret = array(
62 'id' => $id,
63 'finished' => true,
64 'percent' => 100,
65 'total' => $ret['total'],
66 'complete' => $ret['total'],
67 'plugin' => $ID_KEY
71 $_SESSION[$SESSION_KEY][$id] = $ret;
73 return $ret;