cvs: pear /HTML_Progress/examples/upload download.gif formbasic.php formpopup.php formselfref.php hbar.php http1.html http2.html http3.html http4.html
logsupload.html mixedupload.html mixedupload.php progressbar.php selfref.html vbar.php

From: Date: Sat, 26 Jun 2004 12:22:52 +0000
Subject: cvs: pear /HTML_Progress/examples/upload download.gif formbasic.php formpopup.php formselfref.php hbar.php http1.html http2.html http3.html http4.html
logsupload.html mixedupload.html mixedupload.php progressbar.php selfref.html vbar.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-21154@lists.php.net to get a copy of this message
farell Sat Jun 26 08:22:52 2004 EDT Added files: /pear/HTML_Progress/examples/upload download.gif formbasic.php formpopup.php formselfref.php hbar.php http1.html http2.html http3.html http4.html logsupload.html mixedupload.html mixedupload.php progressbar.php selfref.html vbar.php Log: added new examples about web http upload and html_progress (1.1 or better)

http://cvs.php.net/co.php/pear/HTML_Progress/examples/upload/formbasic.php?r=1.1&p=1 Index: pear/HTML_Progress/examples/upload/formbasic.php +++ pear/HTML_Progress/examples/upload/formbasic.php <?php @include '../include_path.php'; /** * Frameset Page Upload * A form is used to select and submit any kind of file to webserver (frame 1) while * a progress meter is running in indeterminate mode in the bottom of page (frame 2) * * @version $Id: formbasic.php,v 1.1 2004/06/26 12:22:52 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress */ require_once 'HTML/QuickForm.php'; function myProcess($values) { global $form; $destination = './uploads/'; $file =& $form->getElement('tstUpload'); if ($file->isUploadedFile()) { $ok = $file->moveUploadedFile($destination); if ($ok) { // write the semaphore to tell progress meter to stop // in script 'progressbar.php' $fp = fopen($destination . $_GET['ID'],'w',false); fwrite($fp, 'done'); fclose($fp); } } } ?> <html> <head> <script language="javascript"> <!-- function DoUpload() { theUniqueID = (new Date()).getTime() % 1000000000; parent.meter.window.location = "hbar.php?ID=" + theUniqueID; parent.files.selfref.action = "formbasic.php?ID=" + theUniqueID; parent.files.selfref.submit(); } //--> </script> </head> <body> <?php $form =& new HTML_QuickForm('selfref'); // We need an additional label below the element $renderer =& $form->defaultRenderer(); $renderer->setElementTemplate(<<<EOT <tr> <td align="right" valign="top" nowrap="nowrap"><!-- BEGIN required --><span style="color: #ff0000">*</span><!-- END required --><b>{label}</b></td> <td valign="top" align="left"> <!-- BEGIN error --><span style="color: #ff0000">{error}</span><br /><!-- END error -->{element} <!-- BEGIN label_2 --><br/><span style="font-size: 80%">{label_2}</span><!-- END label_2 --> </td> </tr> EOT ); $form->addElement('header', null, 'Uploaded file rules'); $form->addElement('file', 'tstUpload', array('Upload file:', 'Rule types: \'uploadedfile\'')); $form->addRule('tstUpload', 'Upload is required', 'uploadedfile'); $form->addElement('header', null, 'Submit the form'); $submit[] =& $form->createElement('button', null, 'Upload', array('onClick'=>'DoUpload();')); $form->addGroup($submit, null, null, '&nbsp;', false); $form->applyFilter('__ALL__', 'trim'); if ($form->validate()) { // Form is validated, then processes the data $form->freeze(); $form->process('myProcess', true); echo '<p>&lt;&lt; <a target="_top" href="../index.html">Back examples TOC</a></p>'; } elseif (isset($_GET['ID'])) { $destination = './uploads/'; $fp = fopen($destination . $_GET['ID'],'w',false); fwrite($fp, 'error'); fclose($fp); } $form->display(); ?> http://cvs.php.net/co.php/pear/HTML_Progress/examples/upload/formpopup.php?r=1.1&p=1 Index: pear/HTML_Progress/examples/upload/formpopup.php +++ pear/HTML_Progress/examples/upload/formpopup.php <?php @include '../include_path.php'; /** * Single Page Upload * A form is used to select and submit any kind of file to webserver * while a progress meter is running in indeterminate mode inside a popup. * * @version $Id: formpopup.php,v 1.1 2004/06/26 12:22:52 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress */ require_once 'HTML/QuickForm.php'; function myProcess($values) { global $form; $destination = './uploads/'; $file =& $form->getElement('tstUpload'); if ($file->isUploadedFile()) { $ok = $file->moveUploadedFile($destination); if ($ok) { // write the semaphore to tell progress meter to stop // in script 'progressbar.php' $fp = fopen($destination . $_GET['ID'],'w',false); fwrite($fp, 'done'); fclose($fp); } } } ?> <html> <head> <script language="javascript"> <!-- function DoUpload() { theFeats = "height=100,width=250,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no"; theUniqueID = (new Date()).getTime() % 1000000000; window.open("progressbar.php?ID=" + theUniqueID, theUniqueID, theFeats); document.formpopup.action = "formpopup.php?ID=" + theUniqueID; document.formpopup.submit(); } //--> </script> </head> <body> <?php $form =& new HTML_QuickForm('formpopup'); // We need an additional label below the element $renderer =& $form->defaultRenderer(); $renderer->setElementTemplate(<<<EOT <tr> <td align="right" valign="top" nowrap="nowrap"><!-- BEGIN required --><span style="color: #ff0000">*</span><!-- END required --><b>{label}</b></td> <td valign="top" align="left"> <!-- BEGIN error --><span style="color: #ff0000">{error}</span><br /><!-- END error -->{element} <!-- BEGIN label_2 --><br/><span style="font-size: 80%">{label_2}</span><!-- END label_2 --> </td> </tr> EOT ); $form->addElement('header', null, 'Uploaded file rules'); $form->addElement('file', 'tstUpload', array('Upload file:', 'Rule types: \'uploadedfile\', \'maxfilesize\' with $format = 10240, \'mimetype\' with $format = \'text/xml\', filename with $format = \'/\\.xml$/\'<br />Validation for files is obviuosly <b>server-side only</b>')); $form->addRule('tstUpload', 'Upload is required', 'uploadedfile'); $form->addRule('tstUpload', 'File size should be less than 10kb', 'maxfilesize', 10240); $form->addRule('tstUpload', 'File type should be text/xml', 'mimetype', 'text/xml'); $form->addRule('tstUpload', 'File name should be *.xml', 'filename', '/\\.xml$/'); $form->addElement('header', null, 'Submit the form'); $submit[] =& $form->createElement('button', null, 'Upload', array('onClick'=>'DoUpload();')); $form->addGroup($submit, null, null, '&nbsp;', false); $form->applyFilter('__ALL__', 'trim'); if ($form->validate()) { // Form is validated, then processes the data $form->freeze(); $form->process('myProcess', true); echo '<p>&lt;&lt; <a target="_top" href="../index.html">Back examples TOC</a></p>'; } elseif (isset($_GET['ID'])) { $destination = './uploads/'; $fp = fopen($destination . $_GET['ID'],'w',false); fwrite($fp, 'error'); fclose($fp); } $form->display(); ?> http://cvs.php.net/co.php/pear/HTML_Progress/examples/upload/formselfref.php?r=1.1&p=1 Index: pear/HTML_Progress/examples/upload/formselfref.php +++ pear/HTML_Progress/examples/upload/formselfref.php <?php @include '../include_path.php'; /** * Frameset Page Upload * A form is used to select and submit any kind of file to webserver (frame 1) while * a progress meter is running in indeterminate mode in the bottom of page (frame 2) * * @version $Id: formselfref.php,v 1.1 2004/06/26 12:22:52 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress */ require_once 'HTML/QuickForm.php'; function myProcess($values) { global $form; $destination = './uploads/'; $file =& $form->getElement('tstUpload'); if ($file->isUploadedFile()) { $ok = $file->moveUploadedFile($destination); if ($ok) { // write the semaphore to tell progress meter to stop // in script 'progressbar.php' $fp = fopen($destination . $_GET['ID'],'w',false); fwrite($fp, 'done'); fclose($fp); } } } ?> <html> <head> <script language="javascript"> <!-- function DoUpload() { theUniqueID = (new Date()).getTime() % 1000000000; parent.meter.window.location = "progressbar.php?ID=" + theUniqueID; parent.files.selfref.action = "formselfref.php?ID=" + theUniqueID; parent.files.selfref.submit(); } //--> </script> </head> <body> <?php $form =& new HTML_QuickForm('selfref'); // We need an additional label below the element $renderer =& $form->defaultRenderer(); $renderer->setElementTemplate(<<<EOT <tr> <td align="right" valign="top" nowrap="nowrap"><!-- BEGIN required --><span style="color: #ff0000">*</span><!-- END required --><b>{label}</b></td> <td valign="top" align="left"> <!-- BEGIN error --><span style="color: #ff0000">{error}</span><br /><!-- END error -->{element} <!-- BEGIN label_2 --><br/><span style="font-size: 80%">{label_2}</span><!-- END label_2 --> </td> </tr> EOT ); $form->addElement('header', null, 'Uploaded file rules'); $form->addElement('file', 'tstUpload', array('Upload file:', 'Rule types: \'uploadedfile\'')); $form->addRule('tstUpload', 'Upload is required', 'uploadedfile'); $form->addElement('header', null, 'Submit the form'); $submit[] =& $form->createElement('button', null, 'Upload', array('onClick'=>'DoUpload();')); $form->addGroup($submit, null, null, '&nbsp;', false); $form->applyFilter('__ALL__', 'trim'); if ($form->validate()) { // Form is validated, then processes the data $form->freeze(); $form->process('myProcess', true); echo '<p>&lt;&lt; <a target="_top" href="../index.html">Back examples TOC</a></p>'; } elseif (isset($_GET['ID'])) { $destination = './uploads/'; $fp = fopen($destination . $_GET['ID'],'w',false); fwrite($fp, 'error'); fclose($fp); } $form->display(); ?> http://cvs.php.net/co.php/pear/HTML_Progress/examples/upload/hbar.php?r=1.1&p=1 Index: pear/HTML_Progress/examples/upload/hbar.php +++ pear/HTML_Progress/examples/upload/hbar.php <?php @include '../include_path.php'; /** * Progress meter is running in indeterminate mode while a file upload operation. * This example may work with HTML_Progress 1.1 * but version 1.2.0 or better allows more easy facilities. * * @version $Id: hbar.php,v 1.1 2004/06/26 12:22:52 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress */ require_once 'HTML/Progress.php'; require_once 'HTML/Progress/observer.php'; class logsUpload extends HTML_Progress_Observer { var $_console; function logsUpload() { $isodate = date('Y-m-d'); $this->_console = './uploads/http4_' . $isodate . '.log'; $this->HTML_Progress_Observer(); } function notify($event) { $semaphore = './uploads/'.$_GET['ID']; if (file_exists($semaphore) && $event['value'] < 100) { $stop = file_get_contents($semaphore); $date = date('H:i:s'); $ip = $_SERVER['REMOTE_ADDR']; $msg = "$date - $ip - file upload: $stop"; error_log("$msg \n", 3, $this->_console); } } } function _methodExists($name) { if (substr(PHP_VERSION,0,1) < '5') { $n = strtolower($name); } else { $n = $name; } if (in_array($n, get_class_methods('HTML_Progress'))) { return true; } return false; } /* User callback called pending progress meter is running, comes with version 1.2.0RC3 */ function myFunctionHandler($progressValue, &$obj) { global $version; global $stop; $semaphore = './uploads/'.$_GET['ID']; if (file_exists($semaphore)) { $stop = file_get_contents($semaphore); $obj->setValue(100); $obj->setIndeterminate(false); $obj->display(); unlink($semaphore); } // sleep a bit ... if ($version > 1.1) { $obj->sleep(); } else { for ($i=0; $i<($obj->_anim_speed*1000); $i++) { } } } /* Which version of html_progress: (stable)1.1 or (beta)1.2.0 RC1, RC2 or RC3 */ $version = _methodExists('run') ? 1.2 : 1.1; $progress = new HTML_Progress(); $observer = new logsUpload(); // prepare the progress meter to logs all upload operations $progress->addListener($observer); $progress->setIncrement(10); $progress->setAnimSpeed(100); $progress->setIndeterminate(true); // progress bar run in indeterminate mode $progress->setStringPainted(true); // get space for the string $progress->setBorderPainted(true); $progress->setString(""); // but don't paint it if ($version > 1.1) { // set a progress handler required at least version 1.2.0RC3 $progress->setProgressHandler('myFunctionHandler'); } $ui = & $progress->getUI(); $ui->setBorderAttributes('width=1 style=inset color=white'); $ui->setCellAttributes(array( 'active-color' => '#000084', 'inactive-color' => '#3A6EA5', 'width' => 25, 'spacing' => 0, 'background-image' => 'download.gif' )); $ui->setStringAttributes(array( 'width' => 60, 'font-size' => 10, 'background-color' => '#C3C6C3' )); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <style type="text/css"> <!-- body { background-color: #C3C6C3; color: #000000; font-family: Verdana, Arial; } <?php echo $progress->getStyle(); ?> // --> </style> <script type="text/javascript"> <!-- <?php echo $progress->getScript(); ?> //--> </script> </head> <body> <?php echo $progress->toHtml(); if (isset($_GET['ID'])) { if ($version > 1.1) { $progress->run(); // run method is born on version 1.2.0RC3 } else { // do the same as run() method do { $progress->display(); myFunctionHandler($progress->getValue(), $progress); if ($progress->getPercentComplete() == 1) { if ($progress->isIndeterminate()) { $progress->setValue(0); } else { break; } } $progress->incValue(); } while(1); } if ($stop == 'error') { echo '<b>File was not uploaded !</b>'; } else { echo '<b>Upload Complete...</b>'; } } ?> </body> </html> http://cvs.php.net/co.php/pear/HTML_Progress/examples/upload/http1.html?r=1.1&p=1 Index: pear/HTML_Progress/examples/upload/http1.html +++ pear/HTML_Progress/examples/upload/http1.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="robots" content="index,nofollow" /> <meta name="keywords" content"="HTML_Progress, HTML_QuickForm, http, upload, form, progress meter" /> <meta name="description" content"="Upload files from a web browser to a web server" /> <meta name="author" content="Laurent Laville" /> <title>PEAR::HTML::Progress example: Web-HTTP ProgressBar uploader</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="../examples.css" /> </head> <body> <a name="top"> <p><a href="../index.html"><img src="../images/home.gif" alt="Examples TOC"/>examples</a></p> <h1><span class="chapter">Web-HTTP ProgressBar uploader </span></h1> <p align="right">$Date: 2004/06/26 12:22:52 $</p> <div class="toc">&nbsp;Table of contents </div> <ul> <li><a href="#intro">Introduction<a> <li><a href="#render">Render options<a> <li><a href="#output">Ouput</a> <li><a href="#source">PHP source syntax highlight<a> <li><a href="#run">Play demo<a> </ul> <a name="intro"> <h2><img src="../images/info.gif"/> Introduction</h2> <p>This example requires : <ul> <li>PEAR::HTML_Progress 1.1 or better.</li> </ul> </p> <hr/> <p><b>This example allows you to upload files from a web browser to your web server.</b></p> <p>It requires no client side software and operates on the server via standard multipart HTML forms as defined in RFC 1867.</p> <p>PEAR::HTML_QuickForm package is used to make and manage the form that will send file to your web server, while HTML_Progress is only used to display a progress meter running in indeterminate mode.</p> <p>Be aware that your web server could returns a timeout on long upload operation, by running the HTML_Progress script (See technical notes below).</p> <p>[<a href="#top">Top</a>]</p> <h2><img src="../images/hands.gif"/>&nbsp;Technical notes </h2> <p>The script time-out refers to the number of seconds a PHP page is given before the script is assumed to have failed and the page terminated. If you are uploading a large file the script that is receiving the transfer may time out before the file has been completely uploaded. To alter this setting you should insert the following code into your uploading page prior to creating any HTML_Progress and HTML_QuickForm objects.</p> <table class="hl-table" width="100%"> <tr> <td class="hl-gutter" align="right" valign="top" style="width:4ex;"> 1 </td> <td class="hl-main" valign="top"> <span class="hl-inlinetags">&lt;?php </span><span class="hl-identifier">set_time_limit</span><span class="hl-brackets">(</span><span class="hl-number">300</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-comment">// five minutes </span><span class="hl-inlinetags">?&gt;</span> </td> </tr> </table> <p>See also: <a target="_blank" href="http://www.php.net/manual/en/function.set-time-limit.php">set_time_limit</a> manual.</p> <p>[<a href="#top">Top</a>]</p> <a name="render"> <h2><img src="../images/config.gif"/>&nbsp;Render options </h2> <pre> increment = 10 (to make progress bar animation smoothest in indeterminate mode) </pre> <div class="fig">HTML_Progress::setIncrement()</div> <pre> speed = 100 (to make progress bar animation smoothest) </pre> <div class="fig">HTML_Progress::setAnimSpeed()</div> <pre> background-color = #e0e0e0 </pre> <div class="fig">HTML_Progress_UI::setProgressAttributes()</div> <pre> color = #996 background-color = #CCCC99 </pre> <div class="fig">HTML_Progress_UI::setStringAttributes()</div> <pre> active-color = #996 </pre> <div class="fig">HTML_Progress_UI::setCellAttributes()</div> <p>[<a href="#top">Top</a>]</p> <a name="output"> <h2><img src="../images/image.gif"/>&nbsp;Output</h2> <h3>Screenshot </h3> <p><img src="../screenshots/upload_selfref.png"/></p> <p>[<a href="#top">Top</a>]</p> <a name="source"> <h2><img src="../images/source.gif"/>&nbsp;PHP source syntax highlight</h2> <p><b>The form file selection:</b> <a target="_blank" href="../highlighter.php?file=upload/formselfref.php">Open</a> source listing in a new window. </p> <p><b>The progress meter in indeterminate mode:</b> <a target="_blank" href="../highlighter.php?file=upload/progressbar.php">Open</a> source listing in a new window. </p> <p>[<a href="#top">Top</a>]</p> <a name="run"> <h2><img src="../images/run.gif"/>&nbsp;Play demo</h2> <p><a href="secure/selfref.html">Run</a> the script.</p> <p>[<a href="#top">Top</a>]</p> </body> </html> http://cvs.php.net/co.php/pear/HTML_Progress/examples/upload/http2.html?r=1.1&p=1 Index: pear/HTML_Progress/examples/upload/http2.html +++ pear/HTML_Progress/examples/upload/http2.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="robots" content="index,nofollow" /> <meta name="keywords" content"="HTML_Progress, HTML_QuickForm, http, upload, form, progress meter" /> <meta name="description" content"="Upload files from a web browser to a web server" /> <meta name="author" content="Laurent Laville" /> <title>PEAR::HTML::Progress example: Web-HTTP ProgressBar uploader</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="../examples.css" /> </head> <body> <a name="top"> <p><a href="../index.html"><img src="../images/home.gif" alt="Examples TOC"/>examples</a></p> <h1><span class="chapter">Web-HTTP ProgressBar uploader </span></h1> <p align="right">$Date: 2004/06/26 12:22:52 $</p> <div class="toc">&nbsp;Table of contents </div> <ul> <li><a href="#intro">Introduction<a> <li><a href="#render">Render options<a> <li><a href="#output">Ouput</a> <li><a href="#source">PHP source syntax highlight<a> <li><a href="#run">Play demo<a> </ul> <a name="intro"> <h2><img src="../images/info.gif"/> Introduction</h2> <p>This example requires : <ul> <li>PEAR::HTML_Progress 1.1 or better.</li> </ul> </p> <hr/> <p><b>This example allows you to upload files from a web browser to your web server.</b></p> <p>PEAR::HTML_QuickForm package is used to make and manage the form that will send file to your web server, while HTML_Progress is only used to display a progress meter running in indeterminate mode inside a windows popup.</p> <p>Be aware that your web server could returns a timeout on long upload operation, by running the HTML_Progress script (See technical notes below).</p> <p>[<a href="#top">Top</a>]</p> <h2><img src="../images/hands.gif"/>&nbsp;Technical notes </h2> <p>The script time-out refers to the number of seconds a PHP page is given before the script is assumed to have failed and the page terminated. If you are uploading a large file the script that is receiving the transfer may time out before the file has been completely uploaded. To alter this setting you should insert the following code into your uploading page prior to creating any HTML_Progress and HTML_QuickForm objects.</p> <table class="hl-table" width="100%"> <tr> <td class="hl-gutter" align="right" valign="top" style="width:4ex;"> 1 </td> <td class="hl-main" valign="top"> <span class="hl-inlinetags">&lt;?php </span><span class="hl-identifier">set_time_limit</span><span class="hl-brackets">(</span><span class="hl-number">300</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-comment">// five minutes </span><span class="hl-inlinetags">?&gt;</span> </td> </tr> </table> <p>See also: <a target="_blank" href="http://www.php.net/manual/en/function.set-time-limit.php">set_time_limit</a> manual.</p> <p>[<a href="#top">Top</a>]</p> <a name="render"> <h2><img src="../images/config.gif"/>&nbsp;Render options </h2> <pre> increment = 10 (to make progress bar animation smoothest in indeterminate mode) </pre> <div class="fig">HTML_Progress::setIncrement()</div> <pre> speed = 100 (to make progress bar animation smoothest) </pre> <div class="fig">HTML_Progress::setAnimSpeed()</div> <pre> background-color = #e0e0e0 </pre> <div class="fig">HTML_Progress_UI::setProgressAttributes()</div> <pre> color = #996 background-color = #CCCC99 </pre> <div class="fig">HTML_Progress_UI::setStringAttributes()</div> <pre> active-color = #996 </pre> <div class="fig">HTML_Progress_UI::setCellAttributes()</div> <p>[<a href="#top">Top</a>]</p> <a name="output"> <h2><img src="../images/image.gif"/>&nbsp;Output</h2> <h3>Screenshot </h3> <p><img src="../screenshots/upload_popup.png"/></p> <p>[<a href="#top">Top</a>]</p> <a name="source"> <h2><img src="../images/source.gif"/>&nbsp;PHP source syntax highlight</h2> <p><b>The form file selection:</b> <a target="_blank" href="../highlighter.php?file=upload/formpopup.php">Open</a> source listing in a new window. </p> <p><b>The progress meter in indeterminate mode:</b> <a target="_blank" href="../highlighter.php?file=upload/progressbar.php">Open</a> source listing in a new window. </p> <p>[<a href="#top">Top</a>]</p> <a name="run"> <h2><img src="../images/run.gif"/>&nbsp;Play demo</h2> <p><a href="secure/formpopup.php">Run</a> the script.</p> <p>[<a href="#top">Top</a>]</p> </body> </html> http://cvs.php.net/co.php/pear/HTML_Progress/examples/upload/http3.html?r=1.1&p=1 Index: pear/HTML_Progress/examples/upload/http3.html +++ pear/HTML_Progress/examples/upload/http3.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="robots" content="index,nofollow" /> <meta name="keywords" content"="HTML_Progress, HTML_QuickForm, http, upload, form, progress meter" /> <meta name="description" content"="Upload files from a web browser to a web server" /> <meta name="author" content="Laurent Laville" /> <title>PEAR::HTML::Progress example: Web-HTTP ProgressBar uploader</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="../examples.css" /> </head> <body> <a name="top"> <p><a href="../index.html"><img src="../images/home.gif" alt="Examples TOC"/>examples</a></p> <h1><span class="chapter">Web-HTTP ProgressBar uploader </span></h1> <p align="right">$Date: 2004/06/26 12:22:52 $</p> <div class="toc">&nbsp;Table of contents </div> <ul> <li><a href="#intro">Introduction<a> <li><a href="#render">Render options<a> <li><a href="#output">Ouput</a> <li><a href="#source">PHP source syntax highlight<a> <li><a href="#run">Play demo<a> </ul> <a name="intro"> <h2><img src="../images/info.gif"/> Introduction</h2> <p>This example requires : <ul> <li>PEAR::HTML_Progress 1.1 or better.</li> </ul> </p> <hr/> <p><b>This example allows you to upload files from a web browser to your web server.</b></p> <p>PEAR::HTML_QuickForm package is used to make and manage the form that will send file to your web server (right frame), while HTML_Progress is only used to display a vertical progress meter running in indeterminate mode (left frame).</p> <p>Be aware that your web server could returns a timeout on long upload operation, by running the HTML_Progress script (See technical notes below).</p> <p>[<a href="#top">Top</a>]</p> <h2><img src="../images/hands.gif"/>&nbsp;Technical notes </h2> <p>The script time-out refers to the number of seconds a PHP page is given before the script is assumed to have failed and the page terminated. If you are uploading a large file the script that is receiving the transfer may time out before the file has been completely uploaded. To alter this setting you should insert the following code into your uploading page prior to creating any HTML_Progress and HTML_QuickForm objects.</p> <table class="hl-table" width="100%"> <tr> <td class="hl-gutter" align="right" valign="top" style="width:4ex;"> 1 </td> <td class="hl-main" valign="top"> <span class="hl-inlinetags">&lt;?php </span><span class="hl-identifier">set_time_limit</span><span class="hl-brackets">(</span><span class="hl-number">300</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-comment">// five minutes </span><span class="hl-inlinetags">?&gt;</span> </td> </tr> </table> <p>See also: <a target="_blank" href="http://www.php.net/manual/en/function.set-time-limit.php">set_time_limit</a> manual.</p> <p>[<a href="#top">Top</a>]</p> <a name="render"> <h2><img src="../images/config.gif"/>&nbsp;Render options </h2> <pre> increment = 5 (to make progress bar animation smoothest in indeterminate mode) </pre> <div class="fig">HTML_Progress::setIncrement()</div> <pre> speed = 100 (to make progress bar animation smoothest) </pre> <div class="fig">HTML_Progress::setAnimSpeed()</div> <pre> color = #000000 with = 1px </pre> <div class="fig">HTML_Progress_UI::setBorderAttributes()</div> <pre> active-color = #970038 inactive-color = #FFDDAA width = 20 height = 20 </pre> <div class="fig">HTML_Progress_UI::setCellAttributes()</div> <pre> count = 20 </pre> <div class="fig">HTML_Progress_UI::setCellCount()</div> <p>[<a href="#top">Top</a>]</p> <a name="output"> <h2><img src="../images/image.gif"/>&nbsp;Output</h2> <h3>Screenshot </h3> <p><img src="../screenshots/upload_mixed.png"/></p> <p>[<a href="#top">Top</a>]</p> <a name="source"> <h2><img src="../images/source.gif"/>&nbsp;PHP source syntax highlight</h2> <p><b>The form file selection:</b> <a target="_blank" href="../highlighter.php?file=upload/mixedupload.php">Open</a> source listing in a new window. </p> <p><b>The progress meter in indeterminate mode:</b> <a target="_blank" href="../highlighter.php?file=upload/vbar.php">Open</a> source listing in a new window. </p> <p>[<a href="#top">Top</a>]</p> <a name="run"> <h2><img src="../images/run.gif"/>&nbsp;Play demo</h2> <p><a href="secure/mixedupload.html">Run</a> the script.</p> <p>[<a href="#top">Top</a>]</p> </body> </html> http://cvs.php.net/co.php/pear/HTML_Progress/examples/upload/http4.html?r=1.1&p=1 Index: pear/HTML_Progress/examples/upload/http4.html +++ pear/HTML_Progress/examples/upload/http4.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="robots" content="index,nofollow" /> <meta name="keywords" content"="HTML_Progress, HTML_QuickForm, http, upload, form, progress meter, logs" /> <meta name="description" content"="Upload and logs files from a web browser to a web server" /> <meta name="author" content="Laurent Laville" /> <title>PEAR::HTML::Progress example: Web-HTTP ProgressBar uploader</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="../examples.css" /> </head> <body> <a name="top"> <p><a href="../index.html"><img src="../images/home.gif" alt="Examples TOC"/>examples</a></p> <h1><span class="chapter">Web-HTTP ProgressBar uploader </span></h1> <p align="right">$Date: 2004/06/26 12:22:52 $</p> <div class="toc">&nbsp;Table of contents </div> <ul> <li><a href="#intro">Introduction<a> <li><a href="#render">Render options<a> <li><a href="#output">Ouput</a> <li><a href="#source">PHP source syntax highlight<a> <li><a href="#run">Play demo<a> </ul> <a name="intro"> <h2><img src="../images/info.gif"/> Introduction</h2> <p>This example requires : <ul> <li>PEAR::HTML_Progress 1.1 or better.</li> </ul> </p> <hr/> <p><b>This example allows you to upload files from a web browser to your web server and logs operations.</b></p> <p>PEAR::HTML_QuickForm package is used to make and manage the form that will send file to your web server (top frame), while HTML_Progress is only used to display a horizontal progress meter running in indeterminate mode (bottom frame).</p> <p>Be aware that your web server could returns a timeout on long upload operation, by running the HTML_Progress script (See technical notes below).</p> <p>To logs all file uploads, we used the observer pattern with HTML_Progress_Observer class. Results are written in a series of files 'http4_[iso date].log', where <i>iso date</i> corresponding to current date in format YYYY-MM-DD.</p> <p>[<a href="#top">Top</a>]</p> <h2><img src="../images/hands.gif"/>&nbsp;Technical notes </h2> <p>The script time-out refers to the number of seconds a PHP page is given before the script is assumed to have failed and the page terminated. If you are uploading a large file the script that is receiving the transfer may time out before the file has been completely uploaded. To alter this setting you should insert the following code into your uploading page prior to creating any HTML_Progress and HTML_QuickForm objects.</p> <table class="hl-table" width="100%"> <tr> <td class="hl-gutter" align="right" valign="top" style="width:4ex;"> 1 </td> <td class="hl-main" valign="top"> <span class="hl-inlinetags">&lt;?php </span><span class="hl-identifier">set_time_limit</span><span class="hl-brackets">(</span><span class="hl-number">300</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-comment">// five minutes </span><span class="hl-inlinetags">?&gt;</span> </td> </tr> </table> <p>See also: <a target="_blank" href="http://www.php.net/manual/en/function.set-time-limit.php">set_time_limit</a> manual.</p> <p>[<a href="#top">Top</a>]</p> <a name="render"> <h2><img src="../images/config.gif"/>&nbsp;Render options </h2> <pre> increment = 10 (to make progress bar animation smoothest in indeterminate mode) </pre> <div class="fig">HTML_Progress::setIncrement()</div> <pre> speed = 100 (to make progress bar animation smoothest) </pre> <div class="fig">HTML_Progress::setAnimSpeed()</div> <pre> color = white with = 1px style = inset </pre> <div class="fig">HTML_Progress_UI::setBorderAttributes()</div> <pre> width = 60 font-size = 10 background-color = #C3C6C3 </pre> <div class="fig">HTML_Progress_UI::setStringAttributes()</div> <pre> active-color = #000084 inactive-color = #3A6EA5 width = 25 spacing = 0 background-image = download.gif </pre> <div class="fig">HTML_Progress_UI::setCellAttributes()</div> <p>[<a href="#top">Top</a>]</p> <a name="output"> <h2><img src="../images/image.gif"/>&nbsp;Output</h2> <h3>Screenshot </h3> <p><img src="../screenshots/upload_logs.png"/></p> <p>[<a href="#top">Top</a>]</p> <a name="source"> <h2><img src="../images/source.gif"/>&nbsp;PHP source syntax highlight</h2> <p><b>The form file selection:</b> <a target="_blank" href="../highlighter.php?file=upload/formbasic.php">Open</a> source listing in a new window. </p> <p><b>The progress meter in indeterminate mode:</b> <a target="_blank" href="../highlighter.php?file=upload/hbar.php">Open</a> source listing in a new window. </p> <p>[<a href="#top">Top</a>]</p> <a name="run"> <h2><img src="../images/run.gif"/>&nbsp;Play demo</h2> <p><a href="secure/logsupload.html">Run</a> the script.</p> <p>[<a href="#top">Top</a>]</p> </body> </html> http://cvs.php.net/co.php/pear/HTML_Progress/examples/upload/logsupload.html?r=1.1&p=1 Index: pear/HTML_Progress/examples/upload/logsupload.html +++ pear/HTML_Progress/examples/upload/logsupload.html <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta name="robots" content="noindex, nofollow" /> <meta name="keywords" content"="HTML_Progress, HTML_Quickform, http, form, upload, progress meter" /> <meta name="description" content"="HTML_Progress and HTML_Quickform the best couple to upload files (protocol http) on a website " /> <meta name="author" content="Laurent Laville" /> <title>PEAR::HTML::Progress example: single page upload</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <frameset rows="*, 100"> <frame name="files" src="formbasic.php" target="_self" /> <frame name="meter" src="hbar.php" target="_self" scrolling="no" /> <noframes> <body> <p>Your browser does not support frames.</p> </body> </noframes> </frameset> </html> http://cvs.php.net/co.php/pear/HTML_Progress/examples/upload/mixedupload.html?r=1.1&p=1 Index: pear/HTML_Progress/examples/upload/mixedupload.html +++ pear/HTML_Progress/examples/upload/mixedupload.html <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta name="robots" content="noindex, nofollow" /> <meta name="keywords" content"="HTML_Progress, HTML_Quickform, http, form, upload, progress meter" /> <meta name="description" content"="HTML_Progress and HTML_Quickform the best couple to upload files (protocol http) on a website " /> <meta name="author" content="Laurent Laville" /> <title>PEAR::HTML::Progress example: mixed field upload</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <frameset cols="100, *"> <frame name="meter" src="vbar.php" target="_self" scrolling="no" /> <frame name="files" src="mixedupload.php" target="_self" /> <noframes> <body> <p>Your browser does not support frames.</p> </body> </noframes> </frameset> </html> http://cvs.php.net/co.php/pear/HTML_Progress/examples/upload/mixedupload.php?r=1.1&p=1 Index: pear/HTML_Progress/examples/upload/mixedupload.php +++ pear/HTML_Progress/examples/upload/mixedupload.php <?php @include '../include_path.php'; /** * Mixed Field Upload * This example shows how to upload a form containing a mix of standard form * and file input fields. * * @version $Id: mixedupload.php,v 1.1 2004/06/26 12:22:52 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress */ require_once 'HTML/QuickForm.php'; function myProcess($values) { global $form; $destination = './uploads/'; $file =& $form->getElement('tstUpload'); if ($file->isUploadedFile()) { $ok = $file->moveUploadedFile($destination); if ($ok) { // write the semaphore to tell progress meter to stop // in script 'progressbar.php' $fp = fopen($destination . $_GET['ID'],'w',false); fwrite($fp, 'done'); fclose($fp); } } } ?> <html> <head> <script language="javascript"> <!-- function DoUpload() { theUniqueID = (new Date()).getTime() % 1000000000; parent.meter.window.location = "vbar.php?ID=" + theUniqueID; parent.files.mixed.action = "mixedupload.php?ID=" + theUniqueID; parent.files.mixed.submit(); } //--> </script> </head> <body> <?php $form =& new HTML_QuickForm('mixed'); // We need an additional label below the element $renderer =& $form->defaultRenderer(); $renderer->setElementTemplate(<<<EOT <tr> <td align="right" valign="top" nowrap="nowrap"><!-- BEGIN required --><span style="color: #ff0000">*</span><!-- END required --><b>{label}</b></td> <td valign="top" align="left"> <!-- BEGIN error --><span style="color: #ff0000">{error}</span><br /><!-- END error -->{element} <!-- BEGIN label_2 --><br/><span style="font-size: 80%">{label_2}</span><!-- END label_2 --> </td> </tr> EOT ); $form->setDefaults(array( 'color' => 'orange' )); $form->addElement('header', null, 'Uploaded file rules'); $form->addElement('file', 'tstUpload', array('What is your favorite picture ?', 'Rule types: \'uploadedfile\', \'maxfilesize\' with $format = 512000, <br />filename with $format = \'/\.(jpe?g|gif|png)$/\'<br />Validation for files is obviuosly <b>server-side only</b>')); $form->addRule('tstUpload', 'Upload is required', 'uploadedfile'); $form->addRule('tstUpload', 'File size should be less than 500kb', 'maxfilesize', 512000); $form->addRule('tstUpload', 'File name should be *.jpg, *.gif or *.png', 'filename', '/\.(jpe?g|gif|png)$/i'); $form->addElement('header', null, 'Assortment of other fields'); $form->addElement('text', 'color', 'What is your favorite color ?'); $checkbox[] = &HTML_QuickForm::createElement('checkbox', 'chocolate', null, 'Chocolate'); $checkbox[] = &HTML_QuickForm::createElement('checkbox', 'butterscotch', null, 'Butterscotch'); $checkbox[] = &HTML_QuickForm::createElement('checkbox', 'vanilla', null, 'Vanilla'); $form->addGroup($checkbox, 'flavor', 'What types of ice cream do you like?', array('&nbsp;', '<br />')); $form->addElement('header', null, 'Submit the form'); $submit[] =& $form->createElement('button', null, 'Upload', array('onClick'=>'DoUpload();')); $form->addGroup($submit, null, null, '&nbsp;', false); $form->applyFilter('__ALL__', 'trim'); if ($form->validate()) { // Form is validated, then processes the data $form->freeze(); $form->process('myProcess', true); echo '<p>&lt;&lt; <a target="_top" href="../index.html">Back examples TOC</a></p>'; } elseif (isset($_GET['ID'])) { $destination = './uploads/'; $fp = fopen($destination . $_GET['ID'],'w',false); fwrite($fp, 'error'); fclose($fp); } $form->display(); ?> http://cvs.php.net/co.php/pear/HTML_Progress/examples/upload/progressbar.php?r=1.1&p=1 Index: pear/HTML_Progress/examples/upload/progressbar.php +++ pear/HTML_Progress/examples/upload/progressbar.php <?php @include '../include_path.php'; /** * Progress meter is running in indeterminate mode while a file upload operation. * This example may work with HTML_Progress 1.1 * but version 1.2.0 or better allows more easy facilities. * * @version $Id: progressbar.php,v 1.1 2004/06/26 12:22:52 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress */ require_once 'HTML/Progress.php'; function _methodExists($name) { if (substr(PHP_VERSION,0,1) < '5') { $n = strtolower($name); } else { $n = $name; } if (in_array($n, get_class_methods('HTML_Progress'))) { return true; } return false; } /* User callback called pending progress meter is running, comes with version 1.2.0RC3 */ function myFunctionHandler($progressValue, &$obj) { global $version; global $stop; $semaphore = './uploads/'.$_GET['ID']; if (file_exists($semaphore)) { $stop = file_get_contents($semaphore); $obj->setValue(100); $obj->setIndeterminate(false); $obj->display(); unlink($semaphore); } // sleep a bit ... if ($version > 1.1) { $obj->sleep(); } else { for ($i=0; $i<($obj->_anim_speed*1000); $i++) { } } } /* Which version of html_progress: (stable)1.1 or (beta)1.2.0 RC1, RC2 or RC3 */ $version = _methodExists('run') ? 1.2 : 1.1; $progress = new HTML_Progress(); $progress->setIncrement(10); $progress->setAnimSpeed(100); $progress->setIndeterminate(true); // progress bar run in indeterminate mode $progress->setStringPainted(true); // get space for the string $progress->setString(""); // but don't paint it if ($version > 1.1) { // set a progress handler required at least version 1.2.0RC3 $progress->setProgressHandler('myFunctionHandler'); } $ui = & $progress->getUI(); $ui->setProgressAttributes(array( 'background-color' => '#e0e0e0' )); $ui->setStringAttributes(array( 'color' => '#996', 'background-color' => '#CCCC99' )); $ui->setCellAttributes(array( 'active-color' => '#996' )); ?> <html> <head> <style type="text/css"> <!-- body { background-color: #CCCC99; color: #996; font-family: Verdana, Arial; } <?php echo $progress->getStyle(); ?> // --> </style> <script type="text/javascript"> <!-- <?php echo $progress->getScript(); ?> //--> </script> </head> <body> <?php echo $progress->toHtml(); if (isset($_GET['ID'])) { if ($version > 1.1) { $progress->run(); // run method is born on version 1.2.0RC3 } else { // do the same as run() method do { $progress->display(); myFunctionHandler($progress->getValue(), $progress); if ($progress->getPercentComplete() == 1) { if ($progress->isIndeterminate()) { $progress->setValue(0); } else { break; } } $progress->incValue(); } while(1); } if ($stop == 'error') { echo '<b>File was not uploaded !</b>'; } else { echo '<b>Upload Complete...</b>'; } } ?> </body> </html> http://cvs.php.net/co.php/pear/HTML_Progress/examples/upload/selfref.html?r=1.1&p=1 Index: pear/HTML_Progress/examples/upload/selfref.html +++ pear/HTML_Progress/examples/upload/selfref.html <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta name="robots" content="noindex, nofollow" /> <meta name="keywords" content"="HTML_Progress, HTML_Quickform, http, form, upload, progress meter" /> <meta name="description" content"="HTML_Progress and HTML_Quickform the best couple to upload files (protocol http) on a website " /> <meta name="author" content="Laurent Laville" /> <title>PEAR::HTML::Progress example: single page upload</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <frameset rows="*, 100"> <frame name="files" src="formselfref.php" target="_self" /> <frame name="meter" src="progressbar.php" target="_self" scrolling="no" /> <noframes> <body> <p>Your browser does not support frames.</p> </body> </noframes> </frameset> </html> http://cvs.php.net/co.php/pear/HTML_Progress/examples/upload/vbar.php?r=1.1&p=1 Index: pear/HTML_Progress/examples/upload/vbar.php +++ pear/HTML_Progress/examples/upload/vbar.php <?php @include '../include_path.php'; /** * Progress meter is running in indeterminate mode while a file upload operation. * This example may work with HTML_Progress 1.1 * but version 1.2.0 or better allows more easy facilities. * * @version $Id: vbar.php,v 1.1 2004/06/26 12:22:52 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress */ require_once 'HTML/Progress.php'; function _methodExists($name) { if (substr(PHP_VERSION,0,1) < '5') { $n = strtolower($name); } else { $n = $name; } if (in_array($n, get_class_methods('HTML_Progress'))) { return true; } return false; } /* User callback called pending progress meter is running, comes with version 1.2.0RC3 */ function myFunctionHandler($progressValue, &$obj) { global $version; global $stop; $semaphore = './uploads/'.$_GET['ID']; if (file_exists($semaphore)) { $stop = file_get_contents($semaphore); $obj->setValue(100); $obj->setIndeterminate(false); $obj->display(); unlink($semaphore); } // sleep a bit ... if ($version > 1.1) { $obj->sleep(); } else { for ($i=0; $i<($obj->_anim_speed*1000); $i++) { } } } /* Which version of html_progress: (stable)1.1 or (beta)1.2.0 RC1, RC2 or RC3 */ $version = _methodExists('run') ? 1.2 : 1.1; $progress = new HTML_Progress(HTML_PROGRESS_BAR_VERTICAL); $progress->setIncrement(5); $progress->setAnimSpeed(100); $progress->setIndeterminate(true); // progress bar run in indeterminate mode $progress->setStringPainted(true); // get space for the string $progress->setString(""); // but don't paint it if ($version > 1.1) { // set a progress handler required at least version 1.2.0RC3 $progress->setProgressHandler('myFunctionHandler'); } $ui = & $progress->getUI(); $ui->setCellCount(20); $ui->setBorderAttributes('width=1 color=#000000'); $ui->setCellAttributes(array( 'active-color' => '#970038', 'inactive-color' => '#FFDDAA', 'width' => 20, 'height' => 20 )); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <style type="text/css"> <!-- body { background-color: White; color: red; font-family: Verdana, Arial; font-size: 10px; } <?php echo $progress->getStyle(); ?> // --> </style> <script type="text/javascript"> <!-- <?php echo $progress->getScript(); ?> //--> </script> </head> <body> <?php echo $progress->toHtml(); if (isset($_GET['ID'])) { if ($version > 1.1) { $progress->run(); // run method is born on version 1.2.0RC3 } else { // do the same as run() method do { $progress->display(); myFunctionHandler($progress->getValue(), $progress); if ($progress->getPercentComplete() == 1) { if ($progress->isIndeterminate()) { $progress->setValue(0); } else { break; } } $progress->incValue(); } while(1); } if ($stop == 'error') { echo '<b>File was not uploaded !</b>'; } else { echo '<b>Upload Complete...</b>'; } } ?> </body> </html>
« previous php.pear.cvs (#21154) next »