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

Source for file mixedupload.php

Documentation is available at mixedupload.php

  1. <?php
  2. @include '../include_path.php';
  3. /**
  4.  * Mixed Field Upload
  5.  * This example shows how to upload a form containing a mix of standard form
  6.  * and file input fields.
  7.  *
  8.  * @version    $Id: mixedupload.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 = "vbar.php?ID=" + theUniqueID;
  42.   parent.files.mixed.action = "mixedupload.php?ID=" + theUniqueID;
  43.   parent.files.mixed.submit();
  44. }
  45. //-->
  46. </script> 
  47. </head>
  48. <body>
  49. <?php
  50.  
  51. $form =new HTML_QuickForm('mixed');
  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->setDefaults(array(
  68.     'color'     => 'orange'
  69. ));
  70.  
  71. $form->addElement('header'null'Uploaded file rules');
  72. $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>'));
  73. $form->addRule('tstUpload''Upload is required''uploadedfile');
  74. $form->addRule('tstUpload''File size should be less than 500kb''maxfilesize'512000);
  75. $form->addRule('tstUpload''File name should be *.jpg, *.gif or *.png''filename''/\.(jpe?g|gif|png)$/i');
  76.  
  77. $form->addElement('header'null'Assortment of other fields');
  78. $form->addElement('text''color''What is your favorite color ?');
  79. $checkbox[&HTML_QuickForm::createElement('checkbox''chocolate'null'Chocolate');
  80. $checkbox[&HTML_QuickForm::createElement('checkbox''butterscotch'null'Butterscotch');
  81. $checkbox[&HTML_QuickForm::createElement('checkbox''vanilla'null'Vanilla');
  82. $form->addGroup($checkbox'flavor''What types of ice cream do you like?'array('&nbsp;''<br />'));
  83.  
  84.  
  85. $form->addElement('header'null'Submit the form');
  86. $submit[=$form->createElement('button'null'Upload'array('onClick'=>'DoUpload();'));
  87. $form->addGroup($submitnullnull'&nbsp;'false);
  88.  
  89. $form->applyFilter('__ALL__''trim');
  90.  
  91. if ($form->validate()) {
  92.     // Form is validated, then processes the data
  93.     $form->freeze();
  94.     $form->process('myProcess'true);
  95.     echo '<p>&lt;&lt; <a target="_top" href="../index.html">Back examples TOC</a></p>';
  96.  
  97. elseif (isset($_GET['ID'])) {
  98.     $destination './uploads/';
  99.     $fp fopen($destination $_GET['ID'],'w',false);
  100.     fwrite($fp'error');
  101.     fclose($fp);  
  102. }
  103. $form->display();
  104. ?>
  105. </body>
  106. </html>

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