HTML_Progress
[ class tree: HTML_Progress ] [ index: HTML_Progress ] [ all elements ]

Source for file formpopup.php

Documentation is available at formpopup.php

  1. <?php
  2. @include '../include_path.php';
  3. /**
  4.  * Single Page Upload
  5.  * A form is used to select and submit any kind of file to webserver
  6.  * while a progress meter is running in indeterminate mode inside a popup.
  7.  *
  8.  * @version    $Id: formpopup.php,v 1.2 2004/07/02 17:49:06 farell Exp $
  9.  * @author     Laurent Laville <pear@laurent-laville.org>
  10.  * @package    HTML_Progress
  11.  */
  12.  
  13. require_once 'HTML/QuickForm.php';
  14.  
  15. function myProcess($values)
  16. {
  17.     global $form;
  18.     $destination './uploads/';
  19.     
  20.     $file =$form->getElement('tstUpload');
  21.     if ($file->isUploadedFile()) {
  22.         $ok $file->moveUploadedFile($destination);
  23.  
  24.         if ($ok{
  25.             // write the semaphore to tell progress meter to stop
  26.             // in script 'progressbar.php'
  27.  
  28.             $fp fopen($destination $_GET['ID'],'w',false);
  29.             fwrite($fp'done');
  30.             fclose($fp);
  31.         }
  32.     }
  33. }
  34. ?>
  35. <html>
  36. <head>
  37. <script language="javascript">
  38. <!--
  39. function DoUpload() {
  40.   theFeats    = "height=100,width=250,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no";
  41.   theUniqueID = (new Date()).getTime() % 1000000000;
  42.   window.open("progressbar.php?ID=" + theUniqueID, theUniqueID, theFeats);
  43.   document.formpopup.action = "formpopup.php?ID=" + theUniqueID;
  44.   document.formpopup.submit();
  45. }
  46. //-->
  47. </script> 
  48. </head>
  49. <body>
  50. <?php
  51.  
  52. $form =new HTML_QuickForm('formpopup');
  53.  
  54. // We need an additional label below the element
  55. $renderer =$form->defaultRenderer();
  56. $renderer->setElementTemplate(<<<EOT
  57. <tr>
  58.     <td align="right" valign="top" nowrap="nowrap"><!-- BEGIN required --><span style="color: #ff0000">*</span><!-- END required --><b>{label}</b></td>
  59.     <td valign="top" align="left">
  60.         <!-- BEGIN error --><span style="color: #ff0000">{error}</span><br /><!-- END error -->{element}
  61.         <!-- BEGIN label_2 --><br/><span style="font-size: 80%">{label_2}</span><!-- END label_2 -->
  62.     </td>
  63. </tr>
  64.  
  65. EOT
  66. );
  67.  
  68. $form->addElement('header'null'Uploaded file rules');
  69. $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>'));
  70. $form->addRule('tstUpload''Upload is required''uploadedfile');
  71. $form->addRule('tstUpload''File size should be less than 10kb''maxfilesize'10240);
  72. $form->addRule('tstUpload''File type should be text/xml''mimetype''text/xml');
  73. $form->addRule('tstUpload''File name should be *.xml''filename''/\\.xml$/');
  74.  
  75. $form->addElement('header'null'Submit the form');
  76. $submit[=$form->createElement('button'null'Upload'array('onClick'=>'DoUpload();'));
  77. $form->addGroup($submitnullnull'&nbsp;'false);
  78.  
  79. $form->applyFilter('__ALL__''trim');
  80.  
  81. if ($form->validate()) {
  82.     // Form is validated, then processes the data
  83.     $form->freeze();
  84.     $form->process('myProcess'true);
  85.     echo '<p>&lt;&lt; <a target="_top" href="../index.html">Back examples TOC</a></p>';
  86.  
  87. elseif (isset($_GET['ID'])) {
  88.     $destination './uploads/';
  89.     $fp fopen($destination $_GET['ID'],'w',false);
  90.     fwrite($fp'error');
  91.     fclose($fp);  
  92. }
  93. $form->display();
  94. ?>
  95. </body>
  96. </html>

Documentation generated on Mon, 11 Mar 2019 13:52:37 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.