Refactored ConfigFile class so that it is no longer a singleton
[phpmyadmin.git] / libraries / display_import_ajax.lib.php
blob275db02a7d824352708628b94a9cd42c3475da96
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Handles plugins that show the upload progress
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
13 * constant for differenciating array in $_SESSION variable
15 $SESSION_KEY = '__upload_status';
17 /**
18 * sets default plugin for handling the import process
20 $_SESSION[$SESSION_KEY]["handler"] = "";
22 /**
23 * unique ID for each upload
25 $upload_id = uniqid("");
27 /**
28 * list of available plugins
30 * Each plugin has own checkfunction in display_import_ajax.lib.php
31 * and own file with functions in upload_#KEY#.php
33 $plugins = array(
34 // PHP 5.4 session-based upload progress is problematic, see bug 3964
35 //"session",
36 "progress",
37 "apc",
38 "noplugin"
41 // select available plugin
42 foreach ($plugins as $plugin) {
43 $check = "PMA_Import_" . $plugin . "Check";
45 if ($check()) {
46 $upload_class = "Upload" . ucwords($plugin);
47 $_SESSION[$SESSION_KEY]["handler"] = $upload_class;
48 include_once "plugins/import/upload/" . $upload_class . ".class.php";
49 break;
53 /**
54 * Checks if APC bar extension is available and configured correctly.
56 * @return boolean true if APC extension is available and if rfc1867 is enabled,
57 * false if it is not
59 function PMA_Import_apcCheck()
61 if (! extension_loaded('apc')
62 || ! function_exists('apc_fetch')
63 || ! function_exists('getallheaders')
64 ) {
65 return false;
67 return (ini_get('apc.enabled') && ini_get('apc.rfc1867'));
70 /**
71 * Checks if UploadProgress bar extension is available.
73 * @return boolean true if UploadProgress extension is available,
74 * false if it is not
76 function PMA_Import_progressCheck()
78 if (! function_exists("uploadprogress_get_info")
79 || ! function_exists('getallheaders')
80 ) {
81 return false;
83 return true;
86 /**
87 * Checks if PHP 5.4 session upload-progress feature is available.
89 * @return boolean true if PHP 5.4 session upload-progress is available,
90 * false if it is not
92 function PMA_Import_sessionCheck()
94 if (PMA_PHP_INT_VERSION < 50400
95 || ! ini_get('session.upload_progress.enabled')
96 ) {
97 return false;
99 return true;
103 * Default plugin for handling import.
104 * If no other plugin is available, noplugin is used.
106 * @return boolean true
108 function PMA_Import_nopluginCheck()
110 return true;
114 * The function outputs json encoded status of uploaded.
115 * It uses PMA_getUploadStatus, which is defined in plugin's file.
117 * @param string $id ID of transfer, usually $upload_id
118 * from display_import_ajax.lib.php
120 * @return void
122 function PMA_importAjaxStatus($id)
124 header('Content-type: application/json');
125 echo json_encode(
126 $_SESSION[$GLOBALS['SESSION_KEY']]['handler']::getUploadStatus($id)