Source for file jFormsControlUpload.class.php

Documentation is available at jFormsControlUpload.class.php

  1. <?php
  2. /**
  3. @package     jelix
  4. @subpackage  forms
  5. @author      Laurent Jouanneau
  6. @contributor Julien Issler
  7. @copyright   2006-2008 Laurent Jouanneau
  8. @copyright   2009 Julien Issler
  9. @link        http://www.jelix.org
  10. @licence     http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
  11. */
  12.  
  13. /**
  14.  *
  15.  * @package     jelix
  16.  * @subpackage  forms
  17.  */
  18. class jFormsControlUpload extends jFormsControl {
  19.     public $type='upload';
  20.     public $mimetype=array();
  21.     public $maxsize=0;
  22.  
  23.     public $fileInfo = array();
  24.  
  25.     function check(){
  26.         if(isset($_FILES[$this->ref]))
  27.             $this->fileInfo = $_FILES[$this->ref];
  28.         else
  29.             $this->fileInfo = array('name'=>'','type'=>'','size'=>0,'tmp_name'=>'''error'=>UPLOAD_ERR_NO_FILE);
  30.  
  31.         if($this->fileInfo['error'== UPLOAD_ERR_NO_FILE{
  32.             if($this->required)
  33.                 return $this->container->errors[$this->refjForms::ERRDATA_REQUIRED;
  34.         }else{
  35.             if($this->fileInfo['error'!= UPLOAD_ERR_OK || !is_uploaded_file($this->fileInfo['tmp_name']))
  36.                 return $this->container->errors[$this->refjForms::ERRDATA_INVALID;
  37.  
  38.             if($this->maxsize && $this->fileInfo['size'$this->maxsize)
  39.                 return $this->container->errors[$this->refjForms::ERRDATA_INVALID;
  40.  
  41.             if(count($this->mimetype)){
  42.                 $this->fileInfo['type'jFile::getMimeType($this->fileInfo['tmp_name']);
  43.                 if $this->fileInfo['type'== 'application/octet-stream'{
  44.                     // let's try with the name
  45.                     $this->fileInfo['type'jFile::getMimeTypeFromFilename($this->fileInfo['name']);
  46.                 }
  47.  
  48.                 if(!in_array($this->fileInfo['type']$this->mimetype))
  49.                     return $this->container->errors[$this->refjForms::ERRDATA_INVALID;
  50.             }
  51.         }
  52.         return null;
  53.     }
  54.  
  55.     function setValueFromRequest($request{
  56.         if(isset($_FILES[$this->ref])){
  57.             $this->setData($_FILES[$this->ref]['name']);
  58.         }else{
  59.             $this->setData('');
  60.         }
  61.     }
  62. }

Documentation generated on Thu, 22 Mar 2012 22:16:05 +0100 by phpDocumentor 1.4.3