[ Index ]
 

Code source de Phorum 5.1.25

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/include/ -> upload_functions.php (source)

   1  <?php
   2  
   3  ////////////////////////////////////////////////////////////////////////////////
   4  //                                                                            //
   5  //   Copyright (C) 2006  Phorum Development Team                              //
   6  //   http://www.phorum.org                                                    //
   7  //                                                                            //
   8  //   This program is free software. You can redistribute it and/or modify     //
   9  //   it under the terms of either the current Phorum License (viewable at     //
  10  //   phorum.org) or the Phorum License that was distributed with this file    //
  11  //                                                                            //
  12  //   This program is distributed in the hope that it will be useful,          //
  13  //   but WITHOUT ANY WARRANTY, without even the implied warranty of           //
  14  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     //
  15  //                                                                            //
  16  //   You should have received a copy of the Phorum License                    //
  17  //   along with this program.                                                 //
  18  ////////////////////////////////////////////////////////////////////////////////
  19  
  20  if ( !defined( "PHORUM" ) ) return;
  21  
  22  /**
  23   * Determines the system's upload limit. This limit is determined by
  24   * the maximum upload filesize (PHP), the maximum POST request size (PHP)
  25   * and the maximum database packet size.
  26   *
  27   * @return An array containing three elements: the overall system's maximum
  28   *         upload size, the maximum as imposed by PHP and the maximum as
  29   *         imposed by the database.
  30   */
  31  function phorum_get_system_max_upload()
  32  {
  33      // Determine limit as imposed by PHP.
  34      $pms = phorum_phpcfgsize2bytes(ini_get('post_max_size'));
  35      $umf = phorum_phpcfgsize2bytes(ini_get('upload_max_filesize'));
  36      $php_limit = ($umf > $pms ? $pms : $umf);
  37  
  38      // Determines the database server's limit for file uploads. This limit
  39      // is determined by the maximum packet size that the database can handle.
  40      // We asume that there's a 40% overhead in the packet, so that 60% of 
  41      // the packet can be used for sending an uploaded file to the database.
  42      $db_limit = phorum_db_maxpacketsize();
  43      if ($db_limit != NULL) {
  44          $db_limit = $db_limit * 0.6;
  45      }
  46  
  47      $limit = $php_limit;
  48      if ($db_limit && $db_limit < $php_limit) {
  49          $limit = $db_limit;
  50      }
  51  
  52      return array($limit, $php_limit, $db_limit);
  53  }
  54  
  55  /**
  56   * Converts the size parameters that can be used in the PHP ini-file
  57   * (e.g. 1024, 10k, 8M) to a number of bytes.
  58   * 
  59   * @param The PHP size parameter
  60   * @return The size parameter, converted to a number of bytes
  61   */
  62  function phorum_phpcfgsize2bytes($val) {
  63      $val = trim($val);
  64      $last = strtolower($val{strlen($val)-1});
  65      switch($last) {
  66         // The 'G' modifier is available since PHP 5.1.0
  67         case 'g':
  68             $val *= 1024;
  69         case 'm':
  70             $val *= 1024;
  71         case 'k':
  72             $val *= 1024;
  73      }
  74      return $val;
  75  }
  76  


Généré le : Thu Nov 29 12:22:27 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics