3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\ProgressBar\Upload
;
13 use Zend\ProgressBar\Exception
;
14 use Zend\Stdlib\ArrayUtils
;
17 * Progress Bar Upload Handler for PHP 5.4+ Session Upload Progress handling
19 class SessionProgress
extends AbstractUploadHandler
24 * @throws Exception\PhpEnvironmentException
26 protected function getUploadProgress($id)
28 if (!$this->isSessionUploadProgressAvailable()) {
29 throw new Exception\
PhpEnvironmentException(
30 'Session Upload Progress is not available'
34 $sessionKey = ini_get('session.upload_progress.prefix') . $id;
35 $uploadInfo = (isset($_SESSION[$sessionKey])) ?
$_SESSION[$sessionKey] : null;
36 if (!is_array($uploadInfo)) {
47 $status = $uploadInfo +
$status;
48 $status['total'] = $status['content_length'];
49 $status['current'] = $status['bytes_processed'];
51 $time = time() - $status['start_time'];
52 $status['rate'] = ($time > 0) ?
$status['bytes_processed'] / $time : 0;
54 if (!empty($status['cancel_upload'])) {
55 $status['done'] = true;
56 $status['message'] = 'The upload has been canceled';
63 * Checks if Session Upload Progress is available
67 public function isSessionUploadProgressAvailable()
69 return (bool) ini_get('session.upload_progress.enabled');