Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/zend/Zend/Validate/File/FilesSize.php
Go to the documentation of this file.
00001 <?php
00025 require_once 'Zend/Validate/File/Size.php';
00026 
00035 class Zend_Validate_File_FilesSize extends Zend_Validate_File_Size
00036 {
00040     const TOO_BIG      = 'fileFilesSizeTooBig';
00041     const TOO_SMALL    = 'fileFilesSizeTooSmall';
00042     const NOT_READABLE = 'fileFilesSizeNotReadable';
00043 
00047     protected $_messageTemplates = array(
00048         self::TOO_BIG      => "All files in sum should have a maximum size of '%max%' but '%size%' were detected",
00049         self::TOO_SMALL    => "All files in sum should have a minimum size of '%min%' but '%size%' were detected",
00050         self::NOT_READABLE => "One or more files can not be read",
00051     );
00052 
00058     protected $_files;
00059 
00069     public function __construct($options)
00070     {
00071         $this->_files = array();
00072         $this->_setSize(0);
00073 
00074         if ($options instanceof Zend_Config) {
00075             $options = $options->toArray();
00076         } elseif (is_scalar($options)) {
00077             $options = array('max' => $options);
00078         } elseif (!is_array($options)) {
00079             require_once 'Zend/Validate/Exception.php';
00080             throw new Zend_Validate_Exception('Invalid options to validator provided');
00081         }
00082 
00083         if (1 < func_num_args()) {
00084             $argv = func_get_args();
00085             array_shift($argv);
00086             $options['max'] = array_shift($argv);
00087             if (!empty($argv)) {
00088                 $options['bytestring'] = array_shift($argv);
00089             }
00090         }
00091 
00092         parent::__construct($options);
00093     }
00094 
00105     public function isValid($value, $file = null)
00106     {
00107         require_once 'Zend/Loader.php';
00108         if (is_string($value)) {
00109             $value = array($value);
00110         }
00111 
00112         $min  = $this->getMin(true);
00113         $max  = $this->getMax(true);
00114         $size = $this->_getSize();
00115         foreach ($value as $files) {
00116             // Is file readable ?
00117             if (!Zend_Loader::isReadable($files)) {
00118                 $this->_throw($file, self::NOT_READABLE);
00119                 continue;
00120             }
00121 
00122             if (!isset($this->_files[$files])) {
00123                 $this->_files[$files] = $files;
00124             } else {
00125                 // file already counted... do not count twice
00126                 continue;
00127             }
00128 
00129             // limited to 2GB files
00130             $size += @filesize($files);
00131             $this->_size = $size;
00132             if (($max !== null) && ($max < $size)) {
00133                 if ($this->useByteString()) {
00134                     $this->_max  = $this->_toByteString($max);
00135                     $this->_size = $this->_toByteString($size);
00136                     $this->_throw($file, self::TOO_BIG);
00137                     $this->_max  = $max;
00138                     $this->_size = $size;
00139                 } else {
00140                     $this->_throw($file, self::TOO_BIG);
00141                 }
00142             }
00143         }
00144 
00145         // Check that aggregate files are >= minimum size
00146         if (($min !== null) && ($size < $min)) {
00147             if ($this->useByteString()) {
00148                 $this->_min  = $this->_toByteString($min);
00149                 $this->_size = $this->_toByteString($size);
00150                 $this->_throw($file, self::TOO_SMALL);
00151                 $this->_min  = $min;
00152                 $this->_size = $size;
00153             } else {
00154                 $this->_throw($file, self::TOO_SMALL);
00155             }
00156         }
00157 
00158         if (count($this->_messages) > 0) {
00159             return false;
00160         }
00161 
00162         return true;
00163     }
00164 }
 All Data Structures Namespaces Files Functions Variables Enumerations