Also apply the __toString fix to UserInfo
[cacert-mgr.git] / external / ZendFramework-1.9.5 / demos / Zend / ProgressBar / Upload.php
1 <?php
2 /**
3 * Zend Framework
4 *
5 * LICENSE
6 *
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.
14 *
15 * @category Zend
16 * @package Zend_ProgressBar
17 * @subpackage Demos
18 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 */
21
22 /**
23 * This sample file demonstrates a simple use case of a jspull-driven progressbar
24 */
25
26 if (isset($_GET['uploadId'])) {
27 set_include_path(realpath(dirname(__FILE__) . '/../../../library')
28 . PATH_SEPARATOR . get_include_path());
29
30 require_once 'Zend/ProgressBar.php';
31 require_once 'Zend/ProgressBar/Adapter/JsPull.php';
32 require_once 'Zend/Session/Namespace.php';
33
34 $data = uploadprogress_get_info($_GET['uploadId']);
35 $bytesTotal = ($data === null ? 0 : $data['bytes_total']);
36 $bytesUploaded = ($data === null ? 0 : $data['bytes_uploaded']);
37
38 $adapter = new Zend_ProgressBar_Adapter_JsPull();
39 $progressBar = new Zend_ProgressBar($adapter, 0, $bytesTotal, 'uploadProgress');
40
41 if ($bytesTotal === $bytesUploaded) {
42 $progressBar->finish();
43 } else {
44 $progressBar->update($bytesUploaded);
45 }
46 }
47 ?>
48 <html>
49 <head>
50 <title>Zend_ProgressBar Upload Demo</title>
51 <style type="text/css">
52 iframe {
53 position: absolute;
54 left: -100px;
55 top: -100px;
56
57 width: 10px;
58 height: 10px;
59 overflow: hidden;
60 }
61
62 #progressbar {
63 position: absolute;
64 left: 10px;
65 top: 50px;
66 }
67
68 .pg-progressbar {
69 position: relative;
70
71 width: 250px;
72 height: 24px;
73 overflow: hidden;
74
75 border: 1px solid #c6c6c6;
76 }
77
78 .pg-progress {
79 z-index: 150;
80
81 position: absolute;
82 left: 0;
83 top: 0;
84
85 width: 0;
86 height: 24px;
87 overflow: hidden;
88 }
89
90 .pg-progressstyle {
91 height: 22px;
92
93 border: 1px solid #748a9e;
94 background-image: url('animation.gif');
95 }
96
97 .pg-text,
98 .pg-invertedtext {
99 position: absolute;
100 left: 0;
101 top: 4px;
102
103 width: 250px;
104
105 text-align: center;
106 font-family: sans-serif;
107 font-size: 12px;
108 }
109
110 .pg-invertedtext {
111 color: #ffffff;
112 }
113
114 .pg-text {
115 z-index: 100;
116 color: #000000;
117 }
118 </style>
119 <script type="text/javascript">
120 function makeRequest(url)
121 {
122 var httpRequest;
123
124 if (window.XMLHttpRequest) {
125 httpRequest = new XMLHttpRequest();
126 if (httpRequest.overrideMimeType) {
127 httpRequest.overrideMimeType('text/xml');
128 }
129 } else if (window.ActiveXObject) {
130 try {
131 httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
132 } catch (e) {
133 try {
134 httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
135 } catch (e) {}
136 }
137 }
138
139 if (!httpRequest) {
140 alert('Giving up :( Cannot create an XMLHTTP instance');
141 return false;
142 }
143
144 httpRequest.onreadystatechange = function() { evalProgress(httpRequest); };
145 httpRequest.open('GET', url, true);
146 httpRequest.send('');
147
148 }
149
150 function observeProgress()
151 {
152 setTimeout("getProgress()", 1500);
153 }
154
155 function getProgress()
156 {
157 makeRequest('Upload.php?uploadId=' + document.getElementById('uploadId').value);
158 }
159
160 function evalProgress(httpRequest)
161 {
162 try {
163 if (httpRequest.readyState == 4) {
164 if (httpRequest.status == 200) {
165 eval('var data = ' + httpRequest.responseText);
166
167 if (data.finished) {
168 finish();
169 } else {
170 update(data);
171 setTimeout("getProgress()", 1000);
172 }
173 } else {
174 alert('There was a problem with the request.');
175 }
176 }
177 } catch(e) {
178 alert('Caught Exception: ' + e.description);
179 }
180 }
181
182 function update(data)
183 {
184 document.getElementById('pg-percent').style.width = data.percent + '%';
185
186 document.getElementById('pg-text-1').innerHTML = data.timeRemaining + ' seconds remaining';
187 document.getElementById('pg-text-2').innerHTML = data.timeRemaining + ' seconds remaining';
188 }
189
190 function finish()
191 {
192 document.getElementById('pg-percent').style.width = '100%';
193
194 document.getElementById('pg-text-1').innerHTML = 'Upload done';
195 document.getElementById('pg-text-2').innerHTML = 'Upload done';
196 }
197 </script>
198 </head>
199 <body>
200 <form enctype="multipart/form-data" method="post" action="Upload.php" target="uploadTarget" onsubmit="observeProgress();">
201 <input type="hidden" name="UPLOAD_IDENTIFIER" id="uploadId" value="<?php echo md5(uniqid(rand())); ?>" />
202 <input type="file" name="file" />
203 <input type="submit" value="Upload!" />
204 </form>
205 <iframe name="uploadTarget"></iframe>
206
207 <div id="progressbar">
208 <div class="pg-progressbar">
209 <div class="pg-progress" id="pg-percent">
210 <div class="pg-progressstyle"></div>
211 <div class="pg-invertedtext" id="pg-text-1"></div>
212 </div>
213 <div class="pg-text" id="pg-text-2"></div>
214 </div>
215 </div>
216 <div id="progressBar"><div id="progressDone"></div></div>
217 </body>
218 </html>