Source of file SessionProgress.php
Size: 2,014 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/ProgressBar/Upload/SessionProgress.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\ProgressBar\Upload; use Zend\ProgressBar\Exception; /** * Progress Bar Upload Handler for PHP 5.4+ Session Upload Progress handling */ class SessionProgress extends AbstractUploadHandler { /** * @param string $id * @return array|bool * @throws Exception\PhpEnvironmentException */ protected function getUploadProgress($id) { if (!$this->isSessionUploadProgressAvailable()) { throw new Exception\PhpEnvironmentException( 'Session Upload Progress is not available' ); } $sessionKey = ini_get('session.upload_progress.prefix') . $id; $uploadInfo = (isset($_SESSION[$sessionKey])) ? $_SESSION[$sessionKey] : null; if (!is_array($uploadInfo)) { return false; } $status = array( 'total' => 0, 'current' => 0, 'rate' => 0, 'message' => '', 'done' => false, ); $status = $uploadInfo + $status; $status['total'] = $status['content_length']; $status['current'] = $status['bytes_processed']; $time = time() - $status['start_time']; $status['rate'] = ($time > 0) ? $status['bytes_processed'] / $time : 0; if (!empty($status['cancel_upload'])) { $status['done'] = true; $status['message'] = 'The upload has been canceled'; } return $status; } /** * Checks if Session Upload Progress is available * * @return bool */ public function isSessionUploadProgressAvailable() { return (bool) ini_get('session.upload_progress.enabled'); } } |