/** * Package constructor * @param UploadSession $uploadSession * @param int $index * @param array $post * @param array $files */ function __construct($uploadSession, $index, $saveIntoCache = false) { if (empty($uploadSession)) { throw new Exception('Upload session can not be null'); } $post = $uploadSession->getRequestFields(); $files = $uploadSession->getRequestFiles(); $this->_uploadSession = $uploadSession; $this->_packageIndex = $index; $uploadSessionId = $uploadSession->getUploadSessionId(); if ($index < $post[PostFields::packageIndex]) { // This is previous package we save for AllPackages event $this->_completed = true; $this->_cached = true; } else { if ($index == $post[PostFields::packageIndex]) { // this package is current package $this->_completed = @(!empty($post[PostFields::packageComplete])); $cache = $this->_uploadSession->getUploadCache(); $this->_cached = $cache->isPackageCached($uploadSessionId, $this->_packageIndex); // If package completed, but already cached then it is last chunk of the package // and we also need to save it. if (!$this->_completed || $this->_cached || $saveIntoCache) { $cache->saveRequestData($uploadSessionId, $this->_packageIndex, $post, $files); $this->_cached = true; } else { $this->_packageFields = $post; $this->_packageFiles = $files; } } else { throw new Exception('Incorrect $index value or POST fields.'); } } }
/** * Returns upload status. * * This is implementation for session.upload_progress in PHP 5.4+. * * @param string $id upload id * * @return array|null */ public static function getUploadStatus($id) { global $SESSION_KEY; if (trim($id) == '') { return null; } if (!array_key_exists($id, $_SESSION[$SESSION_KEY])) { $_SESSION[$SESSION_KEY][$id] = array('id' => $id, 'finished' => false, 'percent' => 0, 'total' => 0, 'complete' => 0, 'plugin' => UploadSession::getIdKey()); } $ret = $_SESSION[$SESSION_KEY][$id]; if (!PMA_import_sessionCheck() || $ret['finished']) { return $ret; } $status = false; $sessionkey = ini_get('session.upload_progress.prefix') . $id; if (isset($_SESSION[$sessionkey])) { $status = $_SESSION[$sessionkey]; } if ($status) { $ret['finished'] = $status['done']; $ret['total'] = $status['content_length']; $ret['complete'] = $status['bytes_processed']; if ($ret['total'] > 0) { $ret['percent'] = $ret['complete'] / $ret['total'] * 100; } } else { $ret = array('id' => $id, 'finished' => true, 'percent' => 100, 'total' => $ret['total'], 'complete' => $ret['total'], 'plugin' => UploadSession::getIdKey()); } $_SESSION[$SESSION_KEY][$id] = $ret; return $ret; }
public function processRequest() { // Ignore other requests except POST. if ($_SERVER['REQUEST_METHOD'] !== 'POST' || empty($_POST[PostFields::packageGuid])) { return; } if (UploadHandler::$_processed) { return; } UploadHandler::$_processed = true; if (array_key_exists('HTTP_X_PREPROCESS_REQUIRED', $_SERVER) && $_SERVER['HTTP_X_PREPROCESS_REQUIRED'] == 'true') { $files = $this->getRequestFiles($_POST); } else { $files =& $_FILES; } $uploadCache = new UploadCache($this->_cacheRoot); $uploadSession = new UploadSession($uploadCache, $_POST, $files, $_SERVER); if (!empty($this->_allFilesUploadedCallback)) { $uploadSession->setAllFilesUploadedCallback($this->_allFilesUploadedCallback); } if (!empty($this->_fileUploadedCallback)) { $uploadSession->setFileUploadedCallback($this->_fileUploadedCallback); } $uploadSession->processRequest(); $this->removeExpiredSessions($uploadCache); // Flash requires non-empty response if (!headers_sent() && array_key_exists('HTTP_USER_AGENT', $_SERVER) && $_SERVER['HTTP_USER_AGENT'] === 'Shockwave Flash') { echo '0'; } }