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

Source for file formselfref.php

Documentation is available at formselfref.php

  1. <?php
  2. @include '../include_path.php';
  3. /**
  4.  * Frameset Page Upload
  5.  * A form is used to select and submit any kind of file to webserver (frame 1) while
  6.  * a progress meter is running in indeterminate mode in the bottom of page (frame 2)
  7.  *
  8.  * @version    $Id: formselfref.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.   theUniqueID = (new Date()).getTime() % 1000000000;
  41.   parent.meter.window.location = "progressbar.php?ID=" + theUniqueID;
  42.   parent.files.selfref.action = "formselfref.php?ID=" + theUniqueID;
  43.   parent.files.selfref.submit();
  44. }
  45. //-->
  46. </script> 
  47. </head>
  48. <body>
  49. <?php
  50.  
  51. $form =new HTML_QuickForm('selfref');
  52.  
  53. // We need an additional label below the element
  54. $renderer =$form->defaultRenderer();
  55. $renderer->setElementTemplate(<<<EOT
  56. <tr>
  57.     <td align="right" valign="top" nowrap="nowrap"><!-- BEGIN required --><span style="color: #ff0000">*</span><!-- END required --><b>{label}</b></td>
  58.     <td valign="top" align="left">
  59.         <!-- BEGIN error --><span style="color: #ff0000">{error}</span><br /><!-- END error -->{element}
  60.         <!-- BEGIN label_2 --><br/><span style="font-size: 80%">{label_2}</span><!-- END label_2 -->
  61.     </td>
  62. </tr>
  63.  
  64. EOT
  65. );
  66.  
  67. $form->addElement('header'null'Uploaded file rules');
  68. $form->addElement('file''tstUpload'array('Upload file:''Rule types: \'uploadedfile\''));
  69. $form->addRule('tstUpload''Upload is required''uploadedfile');
  70.  
  71. $form->addElement('header'null'Submit the form');
  72. $submit[=$form->createElement('button'null'Upload'array('onClick'=>'DoUpload();'));
  73. $form->addGroup($submitnullnull'&nbsp;'false);
  74.  
  75. $form->applyFilter('__ALL__''trim');
  76.  
  77. if ($form->validate()) {
  78.     // Form is validated, then processes the data
  79.     $form->freeze();
  80.     $form->process('myProcess'true);
  81.     echo '<p>&lt;&lt; <a target="_top" href="../index.html">Back examples TOC</a></p>';
  82.  
  83. elseif (isset($_GET['ID'])) {
  84.     $destination './uploads/';
  85.     $fp fopen($destination $_GET['ID'],'w',false);
  86.     fwrite($fp'error');
  87.     fclose($fp);  
  88. }
  89. $form->display();
  90. ?>
  91. </body>
  92. </html>

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