[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/FCKeditor/editor/filemanager/browser/default/connectors/php/ -> commands.php (source)

   1  <?php 
/*
   2   * FCKeditor - The text editor for internet
   3   * Copyright 2006 osCMax2003-2005 Frederico Caldeira Knabben
   4   * 
   5   * Licensed under the terms of the GNU Lesser General Public License:
   6   *         http://www.opensource.org/licenses/lgpl-license.php
   7   * 
   8   * For further information visit:
   9   *         http://www.fckeditor.net/
  10   * 
  11   * File Name: commands.php
  12   *     This is the File Manager Connector for ASP.
  13   * 
  14   * File Authors:
  15   *         Frederico Caldeira Knabben ([email protected])
  16   */
  17  
  18  function GetFolders( $resourceType, $currentFolder )
  19  {
  20      // Map the virtual path to the local server path.
  21      $sServerDir = ServerMapFolder( $resourceType, $currentFolder ) ;
  22  
  23      // Open the "Folders" node.
  24      echo "<Folders>" ;
  25  
  26      $oCurrentFolder = opendir( $sServerDir ) ;
  27  
  28      while ( $sFile = readdir( $oCurrentFolder ) )
  29      {
  30          if ( $sFile != '.' && $sFile != '..' && is_dir( $sServerDir . $sFile ) )
  31              echo '<Folder name="' . ConvertToXmlAttribute( $sFile ) . '" />' ;
  32      }
  33  
  34      closedir( $oCurrentFolder ) ;
  35  
  36      // Close the "Folders" node.
  37      echo "</Folders>" ;
  38  }
  39  
  40  function GetFoldersAndFiles( $resourceType, $currentFolder )
  41  {
  42      // Map the virtual path to the local server path.
  43      $sServerDir = ServerMapFolder( $resourceType, $currentFolder ) ;
  44  
  45      // Initialize the output buffers for "Folders" and "Files".
  46      $sFolders    = '<Folders>' ;
  47      $sFiles        = '<Files>' ;
  48  
  49      $oCurrentFolder = opendir( $sServerDir ) ;
  50  
  51      while ( $sFile = readdir( $oCurrentFolder ) )
  52      {
  53          if ( $sFile != '.' && $sFile != '..' )
  54          {
  55              if ( is_dir( $sServerDir . $sFile ) )
  56                  $sFolders .= '<Folder name="' . ConvertToXmlAttribute( $sFile ) . '" />' ;
  57              else
  58              {
  59                  $iFileSize = filesize( $sServerDir . $sFile ) ;
  60                  if ( $iFileSize > 0 )
  61                  {
  62                      $iFileSize = round( $iFileSize / 1024 ) ;
  63                      if ( $iFileSize < 1 ) $iFileSize = 1 ;
  64                  }
  65  
  66                  $sFiles    .= '<File name="' . ConvertToXmlAttribute( $sFile ) . '" size="' . $iFileSize . '" />' ;
  67              }
  68          }
  69      }
  70  
  71      echo $sFolders ;
  72      // Close the "Folders" node.
  73      echo '</Folders>' ;
  74  
  75      echo $sFiles ;
  76      // Close the "Files" node.
  77      echo '</Files>' ;
  78  }
  79  
  80  function CreateFolder( $resourceType, $currentFolder )
  81  {
  82      $sErrorNumber    = '0' ;
  83      $sErrorMsg        = '' ;
  84  
  85      if ( isset( $_GET['NewFolderName'] ) )
  86      {
  87          $sNewFolderName = $_GET['NewFolderName'] ;
  88  
  89          // Map the virtual path to the local server path of the current folder.
  90          $sServerDir = ServerMapFolder( $resourceType, $currentFolder ) ;
  91  
  92          if ( is_writable( $sServerDir ) )
  93          {
  94              $sServerDir .= $sNewFolderName ;
  95  
  96              $sErrorMsg = CreateServerFolder( $sServerDir ) ;
  97  
  98              switch ( $sErrorMsg )
  99              {
 100                  case '' :
 101                      $sErrorNumber = '0' ;
 102                      break ;
 103                  case 'Invalid argument' :
 104                  case 'No such file or directory' :
 105                      $sErrorNumber = '102' ;        // Path too long.
 106                      break ;
 107                  default :
 108                      $sErrorNumber = '110' ;
 109                      break ;
 110              }
 111          }
 112          else
 113              $sErrorNumber = '103' ;
 114      }
 115      else
 116          $sErrorNumber = '102' ;
 117  
 118      // Create the "Error" node.
 119      echo '<Error number="' . $sErrorNumber . '" originalDescription="' . ConvertToXmlAttribute( $sErrorMsg ) . '" />' ;
 120  }
 121  
 122  function FileUpload( $resourceType, $currentFolder )
 123  {
 124      $sErrorNumber = '0' ;
 125      $sFileName = '' ;
 126  
 127      if ( isset( $_FILES['NewFile'] ) && !is_null( $_FILES['NewFile']['tmp_name'] ) )
 128      {
 129          $oFile = $_FILES['NewFile'] ;
 130  
 131          // Map the virtual path to the local server path.
 132          $sServerDir = ServerMapFolder( $resourceType, $currentFolder ) ;
 133  
 134          // Get the uploaded file name.
 135          $sFileName = $oFile['name'] ;
 136          $sOriginalFileName = $sFileName ;
 137          $sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ;
 138          $sExtension = strtolower( $sExtension ) ;
 139  
 140          global $Config ;
 141  
 142          $arAllowed    = $Config['AllowedExtensions'][$resourceType] ;
 143          $arDenied    = $Config['DeniedExtensions'][$resourceType] ;
 144  
 145          if ( ( count($arAllowed) == 0 || in_array( $sExtension, $arAllowed ) ) && ( count($arDenied) == 0 || !in_array( $sExtension, $arDenied ) ) )
 146          {
 147              $iCounter = 0 ;
 148  
 149              while ( true )
 150              {
 151                  $sFilePath = $sServerDir . $sFileName ;
 152  
 153                  if ( is_file( $sFilePath ) )
 154                  {
 155                      $iCounter++ ;
 156                      $sFileName = RemoveExtension( $sOriginalFileName ) . '(' . $iCounter . ').' . $sExtension ;
 157                      $sErrorNumber = '201' ;
 158                  }
 159                  else
 160                  {
 161                      move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ;
 162  
 163                      if ( is_file( $sFilePath ) )
 164                      {
 165                          $oldumask = umask(0) ;
 166                          chmod( $sFilePath, 0777 ) ;
 167                          umask( $oldumask ) ;
 168                      }
 169  
 170                      break ;
 171                  }
 172              }
 173          }
 174          else
 175              $sErrorNumber = '202' ;
 176      }
 177      else
 178          $sErrorNumber = '202' ;
 179  
 180      echo '<script type="text/javascript">' ;
 181      echo 'window.parent.frames["frmUpload"].OnUploadCompleted(' . $sErrorNumber . ',"' . str_replace( '"', '\\"', $sFileName ) . '") ;' ;
 182      echo '</script>' ;
 183  
 184      exit ;
 185  }
 186  ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7