7
* This source file is subject to the new BSD license that is bundled
8
* with this package in the file LICENSE.txt.
9
* It is also available through the world-wide-web at this URL:
10
* http://framework.zend.com/license/new-bsd
11
* If you did not receive a copy of the license and are unable to
12
* obtain it through the world-wide-web, please send an email
13
* to license@zend.com so we can send you a copy immediately.
16
* @package Zend_ProgressBar
18
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
19
* @license http://framework.zend.com/license/new-bsd New BSD License
23
* This sample file demonstrates an advanced use case of Zend_ProgressBar with
24
* Zend_Form and Zend_File_Transfer.
27
set_include_path(realpath(dirname(__FILE__) . '/../../../library')
28
. PATH_SEPARATOR . get_include_path());
30
if (isset($_GET['progress_key'])) {
31
require_once 'Zend/File/Transfer/Adapter/Http.php';
32
require_once 'Zend/ProgressBar.php';
33
require_once 'Zend/ProgressBar/Adapter/JsPull.php';
35
$adapter = new Zend_ProgressBar_Adapter_JsPull();
36
Zend_File_Transfer_Adapter_Http::getProgress(array('progress' => $adapter));
42
<title>Zend_ProgressBar Upload Demo</title>
43
<style type="text/css">
67
border: 1px solid #c6c6c6;
85
border: 1px solid #748a9e;
86
background-image: url('animation.gif');
98
font-family: sans-serif;
111
<script type="text/javascript">
112
function makeRequest(url)
116
if (window.XMLHttpRequest) {
117
httpRequest = new XMLHttpRequest();
118
if (httpRequest.overrideMimeType) {
119
httpRequest.overrideMimeType('text/xml');
121
} else if (window.ActiveXObject) {
123
httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
126
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
132
alert('Giving up :( Cannot create an XMLHTTP instance');
136
httpRequest.onreadystatechange = function() { evalProgress(httpRequest); };
137
httpRequest.open('GET', url, true);
138
httpRequest.send('');
142
function observeProgress()
144
setTimeout("getProgress()", 1500);
147
function getProgress()
149
makeRequest('ZendForm.php?progress_key=' + document.getElementById('progress_key').value);
152
function evalProgress(httpRequest)
155
if (httpRequest.readyState == 4) {
156
if (httpRequest.status == 200) {
157
eval('var data = ' + httpRequest.responseText);
163
setTimeout("getProgress()", 1000);
166
alert('There was a problem with the request.');
170
alert('Caught Exception: ' + e.description);
174
function update(data)
176
document.getElementById('pg-percent').style.width = data.percent + '%';
178
document.getElementById('pg-text-1').innerHTML = data.text;
179
document.getElementById('pg-text-2').innerHTML = data.text;
184
document.getElementById('pg-percent').style.width = '100%';
186
document.getElementById('pg-text-1').innerHTML = 'Upload done';
187
document.getElementById('pg-text-2').innerHTML = 'Upload done';
193
require_once 'Zend/View.php';
194
require_once 'Zend/Form.php';
196
$form = new Zend_Form(array(
197
'enctype' => 'multipart/form-data',
198
'action' => 'ZendForm.php',
199
'target' => 'uploadTarget',
200
'onsubmit' => 'observeProgress();',
202
'file' => array('file', array('label' => 'File')),
203
'submit' => array('submit', array('label' => 'Upload!'))
207
$form->setView(new Zend_View());
211
<iframe name="uploadTarget"></iframe>
213
<div id="progressbar">
214
<div class="pg-progressbar">
215
<div class="pg-progress" id="pg-percent">
216
<div class="pg-progressstyle"></div>
217
<div class="pg-invertedtext" id="pg-text-1"></div>
219
<div class="pg-text" id="pg-text-2"></div>
222
<div id="progressBar"><div id="progressDone"></div></div>