File indexing completed on 2025-02-23 05:32:03

0001 <?php
0002 
0003 /**
0004  *  ocs-webserver
0005  *
0006  *  Copyright 2016 by pling GmbH.
0007  *
0008  *    This file is part of ocs-webserver.
0009  *
0010  *    This program is free software: you can redistribute it and/or modify
0011  *    it under the terms of the GNU Affero General Public License as
0012  *    published by the Free Software Foundation, either version 3 of the
0013  *    License, or (at your option) any later version.
0014  *
0015  *    This program is distributed in the hope that it will be useful,
0016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0018  *    GNU Affero General Public License for more details.
0019  *
0020  *    You should have received a copy of the GNU Affero General Public License
0021  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0022  **/
0023 class Local_File_Transfer_Adapter_Http extends Zend_File_Transfer_Adapter_Http
0024 {
0025     /**
0026      * @param null $files
0027      *
0028      * @return bool
0029      */
0030     public function isValid($files = null)
0031     {
0032         // Workaround for WebServer not conforming HTTP and omitting CONTENT_LENGTH
0033         $content = 0;
0034         if (isset($_SERVER['CONTENT_LENGTH'])) {
0035             $content = $_SERVER['CONTENT_LENGTH'];
0036         } else {
0037             if (!empty($_POST)) {
0038                 $content = serialize($_POST);
0039             }
0040         }
0041 
0042         // Workaround for a PHP error returning empty $_FILES when form data exceeds php settings
0043         if (empty($this->_files) && ($content > $this->return_bytes(ini_get('post_max_size')))) {
0044             if (is_array($files)) {
0045                 if (0 === count($files)) {
0046                     return false;
0047                 }
0048 
0049                 $files = current($files);
0050             }
0051 
0052             $temp = array(
0053                 $files => array(
0054                     'name'  => $files,
0055                     'error' => 1
0056                 )
0057             );
0058             $validator = $this->_validators['Zend_Validate_File_Upload'];
0059             $validator->setFiles($temp)->isValid($files, null);
0060             $this->_messages += $validator->getMessages();
0061 
0062             return false;
0063         }
0064 
0065         return Zend_File_Transfer_Adapter_Abstract::isValid($files);
0066     }
0067 
0068     /**
0069      * @param string $size_str
0070      *
0071      * @return int
0072      */
0073     private function return_bytes($size_str)
0074     {
0075         switch (substr($size_str, -1)) {
0076             case 'M':
0077             case 'm':
0078                 return (int)$size_str * 1048576;
0079             case 'K':
0080             case 'k':
0081                 return (int)$size_str * 1024;
0082             case 'G':
0083             case 'g':
0084                 return (int)$size_str * 1073741824;
0085             default:
0086                 return $size_str;
0087         }
0088     }
0089 
0090 }