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_NO_TMP_DIR
  36.                || $this->fileInfo['error'== UPLOAD_ERR_CANT_WRITE)
  37.                 return $this->container->errors[$this->refjForms::ERRDATA_FILE_UPLOAD_ERROR;
  38.  
  39.             if($this->fileInfo['error'== UPLOAD_ERR_INI_SIZE
  40.                || $this->fileInfo['error'== UPLOAD_ERR_FORM_SIZE
  41.                || ($this->maxsize && $this->fileInfo['size'$this->maxsize))
  42.                 return $this->container->errors[$this->refjForms::ERRDATA_INVALID_FILE_SIZE;
  43.  
  44.             if($this->fileInfo['error'== UPLOAD_ERR_PARTIAL
  45.                || !is_uploaded_file($this->fileInfo['tmp_name']))
  46.                 return $this->container->errors[$this->refjForms::ERRDATA_INVALID;
  47.  
  48.             if(count($this->mimetype)){
  49.                 $this->fileInfo['type'jFile::getMimeType($this->fileInfo['tmp_name']);
  50.                 if $this->fileInfo['type'== 'application/octet-stream'{
  51.                     // let's try with the name
  52.                     $this->fileInfo['type'jFile::getMimeTypeFromFilename($this->fileInfo['name']);
  53.                 }
  54.  
  55.                 if(!in_array($this->fileInfo['type']$this->mimetype))
  56.                     return $this->container->errors[$this->refjForms::ERRDATA_INVALID_FILE_TYPE;
  57.             }
  58.         }
  59.         return null;
  60.     }
  61.  
  62.     function setValueFromRequest($request{
  63.         if(isset($_FILES[$this->ref])){
  64.             $this->setData($_FILES[$this->ref]['name']);
  65.         }else{
  66.             $this->setData('');
  67.         }
  68.     }
  69. }

Documentation generated on Wed, 24 Sep 2014 21:59:49 +0200 by phpDocumentor 1.4.3