[ Index ]
 

Code source de FCKeditor 2.4

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/editor/filemanager/upload/php/ -> upload.php (source)

   1  <?php 
   2  /*
   3   * FCKeditor - The text editor for Internet - http://www.fckeditor.net
   4   * Copyright (C) 2003-2007 Frederico Caldeira Knabben
   5   * 
   6   * == BEGIN LICENSE ==
   7   * 
   8   * Licensed under the terms of any of the following licenses at your
   9   * choice:
  10   * 
  11   *  - GNU General Public License Version 2 or later (the "GPL")
  12   *    http://www.gnu.org/licenses/gpl.html
  13   * 
  14   *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
  15   *    http://www.gnu.org/licenses/lgpl.html
  16   * 
  17   *  - Mozilla Public License Version 1.1 or later (the "MPL")
  18   *    http://www.mozilla.org/MPL/MPL-1.1.html
  19   * 
  20   * == END LICENSE ==
  21   * 
  22   * File Name: upload.php
  23   *     This is the "File Uploader" for PHP.
  24   * 
  25   * File Authors:
  26   *         Frederico Caldeira Knabben (www.fckeditor.net)
  27   */
  28  
  29  require ('config.php') ;
  30  require ('util.php') ;
  31  
  32  // This is the function that sends the results of the uploading process.
  33  function SendResults( $errorNumber, $fileUrl = '', $fileName = '', $customMsg = '' )
  34  {
  35      echo '<script type="text/javascript">' ;
  36      echo 'window.parent.OnUploadCompleted(' . $errorNumber . ',"' . str_replace( '"', '\\"', $fileUrl ) . '","' . str_replace( '"', '\\"', $fileName ) . '", "' . str_replace( '"', '\\"', $customMsg ) . '") ;' ;
  37      echo '</script>' ;
  38      exit ;
  39  }
  40  
  41  // Check if this uploader has been enabled.
  42  if ( !$Config['Enabled'] )
  43      SendResults( '1', '', '', 'This file uploader is disabled. Please check the "editor/filemanager/upload/php/config.php" file' ) ;
  44  
  45  // Check if the file has been correctly uploaded.
  46  if ( !isset( $_FILES['NewFile'] ) || is_null( $_FILES['NewFile']['tmp_name'] ) || $_FILES['NewFile']['name'] == '' )
  47      SendResults( '202' ) ;
  48  
  49  // Get the posted file.
  50  $oFile = $_FILES['NewFile'] ;
  51  
  52  // Get the uploaded file name extension.
  53  $sFileName = $oFile['name'] ;
  54  
  55  // Replace dots in the name with underscores (only one dot can be there... security issue).
  56  if ( $Config['ForceSingleExtension'] )
  57      $sFileName = preg_replace( '/\\.(?![^.]*$)/', '_', $sFileName ) ;
  58  
  59  $sOriginalFileName = $sFileName ;
  60  
  61  // Get the extension.
  62  $sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ;
  63  $sExtension = strtolower( $sExtension ) ;
  64  
  65  // The the file type (from the QueryString, by default 'File').
  66  $sType = isset( $_GET['Type'] ) ? $_GET['Type'] : 'File' ;
  67  
  68  // Check if it is an allowed type.
  69  if ( !in_array( $sType, array('File','Image','Flash','Media') ) )
  70      SendResults( 1, '', '', 'Invalid type specified' ) ;
  71  
  72  // Get the allowed and denied extensions arrays.
  73  $arAllowed    = $Config['AllowedExtensions'][$sType] ;
  74  $arDenied    = $Config['DeniedExtensions'][$sType] ;
  75  
  76  // Check if it is an allowed extension.
  77  if ( ( count($arAllowed) > 0 && !in_array( $sExtension, $arAllowed ) ) || ( count($arDenied) > 0 && in_array( $sExtension, $arDenied ) ) )
  78      SendResults( '202' ) ;
  79  
  80  $sErrorNumber    = '0' ;
  81  $sFileUrl        = '' ;
  82  
  83  // Initializes the counter used to rename the file, if another one with the same name already exists.
  84  $iCounter = 0 ;
  85  
  86  // Get the target directory.
  87  if ( isset( $Config['UserFilesAbsolutePath'] ) && strlen( $Config['UserFilesAbsolutePath'] ) > 0 )
  88      $sServerDir = $Config['UserFilesAbsolutePath'] ;
  89  else 
  90      $sServerDir = GetRootPath() . $Config["UserFilesPath"] ;
  91  
  92  if ( $Config['UseFileType'] )
  93      $sServerDir .= $sType . '/' ;
  94  
  95  while ( true )
  96  {
  97      // Compose the file path.
  98      $sFilePath = $sServerDir . $sFileName ;
  99  
 100      // If a file with that name already exists.
 101      if ( is_file( $sFilePath ) )
 102      {
 103          $iCounter++ ;
 104          $sFileName = RemoveExtension( $sOriginalFileName ) . '(' . $iCounter . ').' . $sExtension ;
 105          $sErrorNumber = '201' ;
 106      }
 107      else
 108      {
 109          move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ;
 110  
 111          if ( is_file( $sFilePath ) )
 112          {
 113              $oldumask = umask(0) ;
 114              chmod( $sFilePath, 0777 ) ;
 115              umask( $oldumask ) ;
 116          }
 117          
 118          if ( $Config['UseFileType'] )
 119              $sFileUrl = $Config["UserFilesPath"] . $sType . '/' . $sFileName ;
 120          else
 121              $sFileUrl = $Config["UserFilesPath"] . $sFileName ;
 122  
 123          break ;
 124      }
 125  }
 126  
 127  SendResults( $sErrorNumber, $sFileUrl, $sFileName ) ;
 128  ?>


Généré le : Sun Feb 25 15:28:05 2007 par Balluche grâce à PHPXref 0.7